Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bash script error message if else 1

Status
Not open for further replies.

rigstars2

Instructor
Dec 18, 2011
64
US
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
 
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
FAQ181-2886
 
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`
 
Single quotes do not allow the variable substitution. It needs to be in double quotes. But then you need to protect the "[tt]$10[/tt]" with a backslash.

Maybe this?

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


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top