With help of tips from 'here and there' , I just created a simple script to
1. declare one array and some global variables
2. read the schema names from user (user input) and want2proceed flag
3. if user want to proceed , keep reading user input schema name
4. exit the loop if user doesn't want to proceed or it reaches Maximum schema numbers (3)
5 assigns the arrays to global variable only if arrays are not null
This work fine up to this stage . But wants to know any thing could be done to optimize the script or to make the script compact.
And Now I am planning to call other shell scripts with parameter as array value. Its template is also given in the above script .
The basic questions are , Is there any ..
1. change could be done to optimize the script or to make it compact ?
2. function to change the case of input schema name ?
3. technique to validate user input flag (y/n)
4. make the echo and input in the same line.
The shell expands variables (preceded by $) before running the command "[" -- yes, that's right, "[" is a command! If the variable was the empty string, the [ command sees != followed by "n" and never sees the "left hand side" of the argument. So you put it in quotes. Now if the variable is NOT empty, the command works perfectly. Your while loop guarantees the variable will contain something -- either a y or n, so the second instance of [ will always have a y or n after it.
It is recommended always to use the variable with quotes especially during comparison to avoid such errors . Am I right ?
Pretty much, though analytically, you can see that the variable will contain something. However, someone can change the code that breaks that condition.... so better to always quote.
You can also do this trick, often seen in older scripts:
Instead of quoting the variable, you pre- or postfix something to it AND the thing you compare it to.
Thanks very much again for the lightening response .
Shell script sees to be interesting .
But still much difficult section AWK programming , though I am not pretty comfortable with normal shell script.
I am going to get stick on on to it .
The support from the sites like Unix.com may take me to the top of it
Hi Friends,
I'm trying to create a script that allows me to recursively resize, crop (holding the center of the image) and optimize images jpg, jpeg, png for a specific folder and subfolder with the ability to exclude certain folder and its subdirectory.
Again, I should to do with this script:... (3 Replies)
Hi All,
I have written a new script to check for DB space and size of dump log file before it can be imported into a Oracle DB.
I'm relatively new to shell scripting.
Please help me optimize this script further. (0 Replies)
Hello,
I'm wondering if there is a quicker way of doing this.
Here is my mv script.
d=/conversion/program/out
cd $d
ls $d > /home/tempuser/$$tmp
while read line ; do
a=`echo $line|cut -c1-5|sed "s/_//g"`
b=`echo $line|cut -c16-21`
if ;then mkdir... (13 Replies)
Hi,
I need a shell script to determine if a no. is either even, greater than 4, less than 8
SHELL : ksh
OS : RHEL 6
this is the if block of the script
mod=`expr $num % 2`
if || ||
then
echo "No. is either even or greater than 4 or less than 8"
fi
this code works... (2 Replies)
Here is my code. What it does is it reads an input file (input.txt which contains roughly 2,000 search phrases) and searches a directory for files that contains the search phrase. The directory contains roughly 1900 files and 84 subdirectories. The output is a file (output.txt) that shows only the... (23 Replies)
Dear Forum experts
I have the below script which I made to run under bash shell, it runs perfectly for low records number, let us say like 100000. when I put all records (3,000,000), it's takes hours
can you please suggest anything to optimize or to run in different way :-|
{OFS="|";... (6 Replies)
Hi All,
There is a script (test.sh) which is taking more CPU usage. I am attaching the script in this thread.
Could anybody please help me out to optimize the script in a better way.
Thanks,
Gobinath (6 Replies)
I've a script to do some snapshots but the time it does so is very different...
once i got a snapshot under 1 sec, on the other hand it took 3 sec, but nothing else changed, i didnt even move the cursor or something.
I put the script on a ramdisk and its faster, but still swing from under 1... (1 Reply)
Hi,
I have this following script below. Its searching a log file for 2 string and if found then write the strings to success.txt and If not found write strings to failed.txt . if one found and not other...then write found to success.txt and not found to failed.txt.
I want to optimize this... (3 Replies)