LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2009, 01:34 AM   #1
stepic
LQ Newbie
 
Registered: Aug 2006
Posts: 18

Rep: Reputation: 0
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.
 
Old 04-23-2009, 01:57 AM   #2
acerlinux
LQ Newbie
 
Registered: Mar 2009
Posts: 6

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

it does need a character return i guess.
 
Old 04-23-2009, 02:07 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You missed a semi-colon
Code:
a="1"; if [ "$a" = "1" ]; then echo $a; fi
 
Old 04-23-2009, 02:20 AM   #4
stepic
LQ Newbie
 
Registered: Aug 2006
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
You missed a semi-colon
Code:
a="1"; if [ "$a" = "1" ]; then echo $a; fi
You're absolutely right!
It works now.

Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM
Shell command line won't display Jbernoski Slackware 2 03-15-2006 06:31 PM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 09:16 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM
number of command line arguments to shell u4u Linux - General 1 03-04-2005 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration