LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices



Using posix-sh (sh, ksh, bash, ...)

My site (finnish)

My first language is finnish, then
sh, C, awk, K, ... english ...
Sorry about my finglish.
Old

If - how to use

Posted 12-05-2008 at 03:27 AM by kshfi (Jukka's script corner)
Updated 12-07-2008 at 10:57 AM by kshfi
Tags bash, ksh

Programmers - shell if is command.

Code:
if command exit code is 0
then
    do something 1
    do something 2
fi
Ex.
Code:
if  cp fromfile tofile
then
   echo "Works fine"
else
   echo "Error ???"
fi
[ = test
You can write test or [

Code:
a=1
b=1
test "$a" = "$b"
echo $?
0

a=1
b=2
...
LQ Newbie
Views 1187 Comments 0 kshfi is offline

  



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

Main Menu
Advertisement

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration