×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

bash script error message if else

bash script error message if else

bash script error message if else

(OP)
Here is a snippet of my bash code ..can't seem to figure out the error I get; however, if I comment out the first 2 if statements ..it runs fine ..the error I get is "syntax error: unexpected end of file", points the last line

if [[ $# -eq 0 || $# -gt 1 ]] && usage
if [[ $1 != "process1" || $1 != "process2" ]] && usage

if [ "$1" = "$DB" ]; then
echo "$1 process already running..."
exit 1
else
restart_process
fi

RE: bash script error message if else

Replace this:
if [[ $# -eq 0 || $# -gt 1 ]] && usage
if [[ $1 != "process1" || $1 != "process2" ]] && usage
with either this:
[[ $# -eq 0 || $# -gt 1 ]] && usage
[[ $1 != "process1" || $1 != "process2" ]] && usage
or this:
if [[ $# -eq 0 || $# -gt 1 ]]; then usage; fi
if [[ $1 != "process1" || $1 != "process2" ]]; then usage; fi

In fact, I'd use this:
[[ $# -eq 1 ]] || usage
[[ $1 != "process1" && $1 != "process2" ]] && usage

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: bash script error message if else

(OP)
I'm calling my script like this: ./processName wws2

below is my syntax, how can I use the argument I'm passing to this command below..doesn't seem to like it being passed in as a parameter?

VAR=`ps -ef | grep apdel | awk '/$1/ {print $10}' | cut -d\/ -f5`

RE: bash script error message if else

Single quotes do not allow the variable substitution. It needs to be in double quotes. But then you need to protect the "$10" with a backslash.

Maybe this?

CODE

VAR=`ps -ef | grep apdel | awk "/$1/ {print \$10}" | cut -d\/ -f5` 


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close