Small part of Bash Script that I would like to explain it to me
Hi folks,
I do not have experience with Linux bash scripting and I need to write the script in Java which I have to know the function of every line before starting programming in Java. I have a part of the script that I could not understand: #------------------------------------------------------- #!bin/bash # HOME=/u/cluster/mike LOG=$HOME/tmp/fw.log LOCK=$HOME/tmp/fw.lock export HOME LOG LOCK dbg = 0 if [ ${#1} - gt 0 ]; then [ $1 = "-d" ] && dbg = 1 && echo "Debug mode" #------------------------------------------------------- I do not understand : if [ ${#1} - gt 0 ]; then [ $1 = "-d" ] && dbg = 1 && echo "Debug mode" Could you please help me to explain what does it means especially ${#1} and $1 ="-d" Thanks in advance; Jefn |
Code:
do not understand : |
Slight clarification - ${#1} should give the length of the string in ${1}.
Dave |
Quote:
|
Quote:
- g Space allowed between '-' and 'g'? dbg = 1 && Why using the result of 'dbg = 1' to execute the echo command? Since when spaces are allowed in an assignment? Maybe the code works, just as with the ${#1} statement, it might work, but it all is very sloppy. Shame on the original programmer. jlinkels |
Quote:
You said it is he number of arguments passed. But, I did not set a value above and where is it passed. I posted the top of the code and if you see it is not defined before in the file. Thanks very much for your help |
Quote:
But if see the code ${1} is not defined before, so how can I get the length and it is not defined in the code. Thanks Dave for the explanation :) |
Quote:
The main purpose of this part of the code is to check if there is wrong with the system. if there , then echo debug and exit. I could not understand the code, it is really strange and I have NO idea about linux shell scripts. I am mainly in Java :( |
Quote:
Code:
./script.sh mickey mouse donald duck If you read a bash programming guide you will find the arguments referred as "positional parameters". Check for them in the Advanced Bash Scripting Guide or any other Bash manual. |
Quote:
|
thanks mate
Quote:
lol, you are right. the problem that I have to follow its procedure to program in Java and I don't have Ideas how to use Linux scripting, I have just started to learn it but I have time limits. Do you have an idea how to get the IP address and certificate information of a certain user request using scripting?. In my case, I would use it to authenticate a Globus (Grids application) user to open ports 2811 and 2119. |
All times are GMT -5. The time now is 07:48 PM. |