LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   IF condition in shell command line (https://www.linuxquestions.org/questions/programming-9/if-condition-in-shell-command-line-721077/)

stepic 04-23-2009 01:34 AM

IF condition in shell command line
 
I have some trouble entering if-then condition in a single line on a command prompt.

I am trying this one:
Code:

a="1" ; if [ "$a" = "1"  ]; then echo $a fi
The promt response with a > sign and I don't get the echo.

If I paste the same code into the command line, with enters, it returns the result as expected:
Code:

a="1" ;
if [ "$a" = "1"  ]; then
  echo $a
fi

How could this be done in command line, using one line command?
Thanks.

acerlinux 04-23-2009 01:57 AM

a="1" ; if [ "$a" = "1" ]; then (hit Enter) echo $a (hitEnter) fi

it does need a character return i guess.

colucix 04-23-2009 02:07 AM

You missed a semi-colon
Code:

a="1"; if [ "$a" = "1" ]; then echo $a; fi

stepic 04-23-2009 02:20 AM

Quote:

Originally Posted by colucix (Post 3518044)
You missed a semi-colon
Code:

a="1"; if [ "$a" = "1" ]; then echo $a; fi

You're absolutely right!
It works now.

Thank you.


All times are GMT -5. The time now is 09:23 PM.