Search This Blog

Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts

Friday, May 08, 2015

Use variable in search pattern in awk

Passing a variable to awk and using it in the search pattern.



awk -v string="$STRING" -f  script.awk  [filename]

Script extract:

$0 ~ string {
      
       print $0;
}

Note:

        On Solaris use nawk.

Monday, January 26, 2015

Variable assigments

Validating positional parameters.

The below example will print a usage message if there is no 2nd position paramaeter.

PACKAGE=${2:?$(usage ${SERVERLIST} [Package name:Version:Package file[:Dependent service]])}

Tuesday, June 28, 2011

Shell Scripting: basename variable

"${0##*/}" is the equivalent of "basename $0".
I.e. From /usr/bin/sh we get just sh.


Also try this to execute commands $(shell command)

Thursday, May 17, 2007

Shell scripting: Testing empty variables

$V="xNotEmpty"

if [ x$V = "xNotEmpty" ]
then
       echo "\$V not empty"
else
       echo"\$V is empty"
fi

Or:

if [ "$V" = "" ]
then
      echo "\$V is empty
fi

Friday, September 01, 2006

Shell Scripting: Special Variables

  • $? Exit status or return code of last command.
  • $# Number of arguments.
  • $@ Argument 1 thru n with Input Field Separator.
  • $* "$1" $2" ... $n.
  • $! Process id of last background process.
  • $$ Process id of shell running this script.
  • $- The current shell flags.