Bash

From Halfface
Revision as of 05:06, 24 January 2008 by 192.168.2.8 (talk)
Jump to navigation Jump to search

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

$1 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,