shell variable

I have setup a master / local server combination using OpenSSH. My local server depends upon master server for a remote sourcing. The remote sourcing should set a large number of variables locally in a bash shell script. The code is:

user@slave $ source ssh user@master "/service/dyn.master.setenv.sh --mode=slave"
echo “$var”

The var is not setting and I am getting various errors. How can I do a remote “source” of a bash script file (from master.example.com) and set a shell variable locally at slave.example.com?

{ 0 comments }

I work for a small ISP (Internet Service Provider) and we are using Linux and Unix-like operating system with bash shell. I want to write a shell script to parse the csv file line by line. Then line must be parse again field by field. The sample input file is as follows:

example.com,username,groupname,homedir,md5password,permission,secondarygroup

I need to extract each of these example.com,username,groupname,homedir,md5password,permission,secondarygroup fields and passed to the different system utilities. How do I write a shell script to automate this task and use the bash shell to parse a text file?

{ 7 comments }

I‘m writing a bash wrapper script that will pass arguments to the command. I need to find out the last argument if I call the wrapper as follows:

./wrapper -a -b –longarg=foo thisfilename.txt
./wrapper -a -b thisfilename.txt
./wrapper -a –next=true thisfilename.txt



Where,

=> $@ is all of them.

=> $0 is script name.

=> $1 is first arg.




I want thisfilename.txt stored in a shell variable called $last. How do I find the last argument passed to a shell script written in bash or ksh under Unix like operating systems?

{ 1 comment }

I‘m writing a shell script for automation purpose. The output the path of the current working directory is stored in $PWD or it can be obtained using the pwd command. How do I find out find out 3rd field separated by the forward slash (/) delimiter using $PWD under Unix like operating systems?

{ 8 comments }

How do I set or create variables within my shell script or at command line under Linux and Unix like operating systems?

{ 0 comments }

I‘m using the date +’%D_%T’ to store Unix system date and time in a shell variable called $_now:

_now=”$(date +’%D_%T’)”
echo $_now

Outputs:
01/20/12_16:10:42

I’d like to replace / and : with _. I’m aware of the following sed command:

sed ‘s/\//_/g
> s/:/_/g’ <<<"$_now"

Outputs:
01_20_12_16_14_09

How do I specify two pattern within the same sed command to replace | and : with _ so that I can get output as 01_20_12_16_10_42?

{ 3 comments }

How do I assign printf command result to a shell variable under Unix like operating systems?

{ 0 comments }