variables


$BASH_VERSION

$RANDOM
$SECONDS
-------------
cat pid.sh
echo "Process $$ Starting up with arguments $@ for parent $PPID"
$$ special variable which provides the process ID of this shell itself
PPID is set to the process ID of the process that called this shell or shell script
./pid.sh 1
Process 26249 Starting up with arguments 1 for parent 19260
SECONDS – returns a count of the number of seconds the shell has been running
-------------
echo $HOME
/home/ok74010
PATH is a colon-separated list of directories used to find program files. It’s searches left-to-right
You can read a list of hashed paths by running hash –l, to remove hash –r
In PATH, a period (.) is used to represent the current directory of the calling program.
Less well known is that a double colon (: :) will do the same, and a single colon at the beginning or end of the PATH variable will also expand to the current working directory.

From security perspective, it is very bad practice to put a dot . in your PATH, especially at the front of the PATH.

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

-------------
$ ll fil??
$ ls f*a*
$ ls a?b*
$ ls –ld /etc/rc{0,1,2,3,4}.d
ll fi{l,w}?
-rw-r--r-- 1 0 Jul 20 14:36 fil2
-rw-r--r-- 1 0 Jul 20 08:35 file
-rw-r--r-- 1 0 Jul 20 14:36 fiw2
fi[a-z]?
-rw-r--r-- 1 0 Jul 20 14:36 fil2
-rw-r--r-- 1 0 Jul 20 08:35 file
-rw-r--r-- 1 0 Jul 20 14:36 fiw2
-------------

[shell scripting p40]
ubuntu2@ubuntu2:~/temp$ cat var1
#!/bin/bash
echo “My name is `basename $0` - I was called as $0”
echo “I was called with $# parameters.”
count=1
while [ "$#" -ge "1" ]; do
echo “Parameter number $count is: $1”
let count=$count+1
shift
done
ubuntu2@ubuntu2:~/temp$ 


ubuntu2@ubuntu2:~/temp$ bash var1 1 2 3
“My name is var1 - I was called as var1”
“I was called with 3 parameters.”
“Parameter number 1 is: 1”
“Parameter number 2 is: 2”
“Parameter number 3 is: 3”

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all