In shell code you are concerned about: efficiency and readability
The former because you want to minimize the impact of your code on the system, the latter because you and others will have to change this stuff X years from now when you have completely forgotten about it, and it no longer works the way you need.
Either of these is equally fast:
Code:
a=$b
((a=b))
The first one is more conventional, and is more likely to port.
[ is a bash builtin, [[ is a keyword so they both run as part of the shell, as does (( )).
So it boils down to which one is the easiest to for another person to interpret, which is a personal matter.
This User Gave Thanks to jim mcnamara For This Post:
I am thinking of setting the verbosity level using a call to a function.
In the bash script I have two variables
Code:
hasArgument_vbLevel # set to "true" if user specified vbLevel
value_vbLevel # contains the verbosity level of the user
I would want to call the function and pass it value_vbLevel. The function setVerbosity
will set vbLevel which will be used in the script.
In the script I will have
Code:
value_vbLevel=$1 # User inputs " none", "low", "medium", "high" or "debug"
none=0; low=1; medium=2; high=3; debug=4
vbLevel=$medium # Set default verbosity
if [ "$hasArgument_vbLevel" == "true" ]; then
setVerbosity $value_vbLevel # In the program I would use vbLevel. Need to set vbLevel somehow
fi
if [ $vbLevel -gt $low ]; then # Example of use of the vbLevel as number 0-4
...
fi
Here I have started doing some code, but need some help and suggestions on the way forward.
Code:
function setVerbosity() {
# -- Check for valid verbosity level -------------------------------------------------------------
local locl_vbLevelStr=$1
isVbLevel="false"
for vb in "none" "low" "medium" "high" "debug"
do
echo $vb
if [ "$locl_vbLevelStr" == "$vb" ]; then
isVbLevel="true"
fi
done
# -- Set verbosity level -------------------------------------------------------------------------
vbLevel="${!locl_vbLevel}"
if [ "$isVbLevel" == "false" ]; then
echo "EXIT"
exit 1
fi
}
I have the following code and into into trying to simplifying it. Any suggestions please?
pmin = min (p(1), p(2), p(3), p(4), p(5), p(6))
ni = 0
xint = 0.0
yint = 0.0
zint = 0.0
!--------------------------------------------- !
if ((0.99999 * p(1)) <= pmin) then
... (3 Replies)
Hi All,
I have a file menu_opts is as follows
# cat menu_opts
Please select the options
qqqq_usb STD RETAIL Progs (Prime time cue advertisements)
qqqq_onc STD Dealer Progs (Prime time cue advertisements)
qqqq_zt_usb STD RETAIL Progs (Long Format cue... (2 Replies)
hey,
I have text file which has some data for some device Id's. i want to perform AVG, MAX,2nd MAX on these device ids. The .txt file looks like below. please help me in finding the computations per Device id. My output file should contatin with DeviceID,Avg, max and 2nd max of the device ID.... (8 Replies)
Hi,
I'm quite new to scripting, but know a few AWK statements.
I have the following line in my script:
hostname=`echo $file | awk 'BEGIN{FS=OFS="."}{$NF=""; NF--; print}'`
I use this in my script to rename files, which are similar to this:
name.mvkf.mkvfm.mkfvm.1
To the... (4 Replies)
Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is:
1702938475,SNU022,201004
the first 10 numbers always begin with 170 (6 Replies)
Is there an easy way using a command or other routine for testing whether an argument on the command line is numeric? Just want to validate... I ran a search and didn't find a similar question....
Thx (3 Replies)
I am trying to setup to automatically import a series of mysql database files. I am doing manually now and its a royal pain.
All the sql files are sequentially numbered in a format of 4 numbers underscore text with spaces replaced by underscores.
example:
There are 3 databases each setup... (1 Reply)
Hello folks,
I have data collected in every 3 hours. But, I would like to expand this to 1 hour interval by equally dividing with next row.
For example, I want to keep the first value 1987-01-01-00z 2.0, but following all record should be re-written as follow.
1987-01-01-03z 5.0 becomes... (11 Replies)