know about :


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting know about :
# 1  
Old 05-21-2010
know about :

Code:
C_id=${1:--1} && f_id=${2:--1} && [ ${C_id} -eq -1 ] && Sintaxis

Syntaxis is a function

please make me understand what above statement is doing
and also explain : &&

Last edited by pludi; 05-21-2010 at 06:50 AM.. Reason: code tags, please..
# 2  
Old 05-21-2010
Code:
${var:-word}

If var exists and isn't null, return its value .. otherwise return word.

&& check if previous command successfully run (mean exit status is zero) then go for next command.
# 3  
Old 05-21-2010
This probably does the following:

1. check if $1 ( first argument) is available, if yes assign its value to C_id, if not, assign -1 to C_id.
2. if case one executed successfully. check if $2 ( second argument) is available, if yes assign its value to f_id, if not, assign -1 to f_id.
3. if case 2 executed successfully, compare value if C_id with -1, if its equal to -1, execute the Sintaxis function.

---------- Post updated at 04:02 PM ---------- Previous update was at 03:37 PM ----------

And regarding "&&",

&& and || are the shell construct. which applies the action based on the success or failure of the previous commands.

Code:
cd abc && echo "change dir successfully" || echo "failed to change dir"

In the above code,
if "cd" si successful to change i.e exit code is zero. this will execute the command after "&&". if it failed to change dir, the commands after "||" will be executed.
# 4  
Old 05-21-2010
Maybe if it's written another way
Code:
if [ -z "$1" ]
then C_id=-1
else C_id=$1
fi
if [ -z "$2" ]
then f_id=-1
else f_id=$2
fi
if  [ ${C_id} -eq -1 ]
then Sintaxis
fi

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question