I recently started going in depth with the shell, so I started learning from Linux Shell Scripting CookBook, 2nd edition. I am at the first chapter atm, and the author tells to define a function in the ~/.bashrc.
The function is below.
And another given version is
The function, can be called like:
I managed to define it in bashrc and it works, however I want to understand step by step what it does(basically what each part of the code does and what it means) and unfortunately the author doesn't explain.
I know that basically when called, the function adds, the given path, into the variable that is mentioned. If you say prepend PATH /home/usr it will add /home/usr, to the existing content in the $PATH at the end of what is already in the variable.
Can anybody help with how it works step by step? Sorry if this is a very n00b question, but I don't know whom to ask.
Kind Regards,
George
Last edited by bartus11; 01-10-2014 at 08:10 PM..
Reason: Please use code tags.
well [ is a command for tests. it's about the same as test.
looking at help test we see -d checks to see if $2 exists as a directory before doing anything else.
&& joins the statements. in A && B, B is only performed if A was true. similarly A || B, B is only performed if A was false. (Like short-circuit evaluation in C) Read more in the bash reference manual, section 3.2.3 Lists of Commands
A clearer version would perhaps be eval is rather bad practice, unless absolutely necessary. I personally wouldn't use this function.. So much can go wrong executing user-defined strings as code. But moving past that. It does that: executes the line again... So placing our variables into there we'll see
become as
the single quotes around the colon there isn't very helpful... But neither is this particular function.
Hi All,
Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition.
#Body
function1()
{
if
then
echo "exist"
else
echo "not exist"
}
#if not exist in function1 my all other function will not proceed.... (4 Replies)
Hi,
I am having script which contains many functions. Need to print each function name at the starting of the function. Like below,
functionname()
{
echo "functionname"
commands....
}
I've tried like below,
func=`grep "()" scriptname | cut -d "(" -f1`
for i in $func
do
nawk -v... (4 Replies)
Hello,
I have many folders under which there is always a file with the same name, which contains the data I need to process later. A perl oneliner was borrowed
perl -e 'print "gene_id\t", join("\t", map {/(.*)\//; $1} @ARGV),"\n";' *_test.trim/level.csvto make a header so that each column... (5 Replies)
I have this code
#!/bin/bash
LZ () {
RETVAL="\n$(date +%Y-%m-%d_%H-%M-%S) --- "
return RETVAL
}
echo -e $LZ"Test"
sleep 3
echo -e $LZ"Test"
which I want to use to make logentrys on my NAS. I expect of this code that there would be output like
2017-03-07_11-00-00 --- Test (4 Replies)
Dear All.
I have a script, which process files one by one. In the script I have two functions.
one sftp files to different server
the other from existing file create file with different name.
My question is:
Will sftp function recognize files names , which are created in another... (1 Reply)
I have a script which does gunzip, zip and untar.
Input to the script is file name and file directory (where file is located)
I am reading the input parameters as follows:
FILENAME=$1
FILEDIR=$2
I have created 3 functions that are as follows:
1) gunzip file
2) unzip file... (2 Replies)
In gdb, I can call one function with command "call", but how can I step in the function? I don't want to restart the program, but the function had been executed, gdb will execute next statement, and I don't know how to recall the function. (4 Replies)
There is a function called start:
start()
{
echo -n $"Sending Startup Email: "
echo "${RESTARTBODY}" | mutt -s "${RESTARTSUBJECT}" ${EMAIL}
RETVAL=$?
if ; then
touch ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}
Can anyone explain what the bold part of the... (3 Replies)
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)