I know php programming but I am not familiar with bash script programming syntax.
I have this code snippet
EXPECTEDARGS=0
if [ $# -ne $EXPECTEDARGS -o "x$0" == "x" -o $0 == "bash" ]; then
echo "Usage:"
echo " Parameter 1: argument 1 missing"
exit 1
fi
This correctly checks for at least 1 argument.
I want to understand what this code snippet means line by line. So far, I can only make out that EXPECTEDARGS is a variable.
After understanding the code snippet, I want to modify it to check for 2 arguments.
The code snippet will be in a github gist.
I aim to execute the script using
bash -c "$(curl -fsSL https://raw.github.com/gist/4491019)" <arg1> <arg2>
without the <> symbols of course.
if you want to know more, save the script as a file and try to print stuff with
echo. Run the script with:or
to mimic the behaviour of bash+curl
[ ]ortestis a good example, they are just a program, actually the same program, while checking $0 or argv[0] in C, they behave a little bit different.If you run
[ 2 -gt 1 ]; echo $?it will print 0 in your terminal, 0 means success everything else means failure. If you calltestinstead:test 2 -gt 1; echo $?it also print 0.so
ifjust runs a program and checks the exit code, you can also do:will print: success, 0, 1