Why did I get number 0 logname?
Because of:
Code:
# Initialise "counter"
n=0
# Take all commandline arguments and loop over them
for arg in nissanka df du;
# If the argument we're inspecting matches the logname
# of the currently logged in user, echo some text
if [ nissanka = nissanka ]; then
echo "Number 0 is logname"
fi
It's easier to see values get filled in if you run the script as: "sh -x argument2 nissanka df du".
What is this line doing ---> let n=${n}+
"let" ("help let") does arithmetic expressions, in this case it takes the value of the counter and increments it by one. Another notation could be ((n++)) or n=$[${n}+1]
; shift $n;
When executing a Bash shell script the scriptname occupies variable "$0". Commandline arguments take up positions 1 through * where 1 through 9 are available immediately. If you would like to see the next one you use "shift" ("help shift") "to, ahhh, shift focus.
I urge someone to provide me a with a reply.
...and that's the reason we had your posts moved to your own brand new thread. If we didn't people would think you just replied to the OP (which you didnt, which in the worse cases is called thread hijacking) and would easily miss your questions. So: your questions -> your own thread. And you best wait 24 hours before asking for a reply. Zero-reply threads get bumped automagically so you only have to work on your patience.