Bash: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 53: | Line 53: | ||
w | w | ||
set +x # stop debugging from here | set +x # stop debugging from here | ||
==variables== | |||
Character Definition | |||
$* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. | |||
$@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. | |||
$# Expands to the number of positional parameters in decimal. | |||
$? Expands to the exit status of the most recently executed foreground pipeline. | |||
$- A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i). | |||
$$ Expands to the process ID of the shell. | |||
$! Expands to the process ID of the most recently executed background (asynchronous) command. | |||
$0 Expands to the name of the shell or shell script. | |||
$_ The underscore variable is set at shell startup and contains the absolute file name of the shell or script being executed as passed in the argument list. Subsequently, it expands to the last argument to the previous command, after expansion. It is also set to the full pathname of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file. |
Revision as of 22:46, 25 January 2008
bash Shell
For using multiple filenames in one command in Unix commandline use the following command:
for i in <equal part of all filenames>*;do <command> $i;done
$i is the variable set by the loop.
Example:
for i in sync_m4606_danube_sg_org_*;do /usr/atria/etc/mkorder -data $i -fship blrsxa16.blr.infineon.com;done
More examples:
for i in `ct lsvob |grep systemq | cut -d" " -f4`;do /usr/atria/etc/utils/albd_list -s $i;done
All Files starting with sync_m4606_danube_sg_org_ are used to perform a mkorder -data to forward these packets to Bangalore server.
for i in `cut -f2 -d" " viewlist.del`;do rm -r /home/memhub.view/$i;done
Use viewtags of column 2 of the file viewlist.del to remove the viewstorage.
Alternative
Use xargs for simply passing over results to a simple command:
ps- elf | grep <string> |tr -s " " |cut f<row nr.> -d" "|xargs <command>
tr - text replace with -s for substitute
e.g.:
ps -elf | grep CCMS | tr -s " " | cut -f5 -d" " |xargs kill
loop number
i=0; while [ $i -lt 10 ]; do echo $i; i=`expr $i + 1`; done
interactive shell
echo $- If shell is interactive variable will contain i.
explanation
operand 3, 3 + 6 = 9 '+' is the operator and '3' and '6' are the operands. operator +, 3 + 6 = 9 '+' is the operator and '3' and '6' are the operands. primary That which stands first in order, rank, or importance Arithmetic most elementary branch of mathematics, Command control Testing exit status of a command in order to determine whether a portion of the program should be executed. Conditional branch Logical point in the program when a condition determines what happens next. Logic flow The overall design of the program. Determines logical sequence of tasks so that the result is successful and controlled. Loop Part of the program that is performed zero or more times. User input Information provided by an external source while the program is running, can be stored and recalled when needed.
debug
set -x # activate debugging from here w set +x # stop debugging from here
variables
Character Definition $* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. $@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. $# Expands to the number of positional parameters in decimal. $? Expands to the exit status of the most recently executed foreground pipeline. $- A hyphen expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the -i). $$ Expands to the process ID of the shell. $! Expands to the process ID of the most recently executed background (asynchronous) command. $0 Expands to the name of the shell or shell script. $_ The underscore variable is set at shell startup and contains the absolute file name of the shell or script being executed as passed in the argument list. Subsequently, it expands to the last argument to the previous command, after expansion. It is also set to the full pathname of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.