Bash

From Halfface
Revision as of 17:39, 25 January 2008 by 192.168.2.87 (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

$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