IT's a synonym for test, it returns true or false.
That code fragment means: test if $ERROROUTPUT is zero length || echo "$TITLE"
It doesn't make much sense in a programming context because the || allows the echo part to run regardless - it is a boolean or
i.e., the echo happens whether the first test evaluates true or false...
IT's a synonym for test, it returns true or false.
That code fragment means: test if $ERROROUTPUT is zero length || echo "$TITLE"
It doesn't make much sense in a programming context because the || allows the echo part to run regardless - it is a boolean or
i.e., the echo happens whether the first test evaluates true or false...
I beg to differ, "||" is and works as an else...
...testing if .bash_history is a file:
The form "[ ]" is essentially calling the external "test" command, and thus everything is evaluated by the shell first. That's why you get "test: argument expected" when an unquoted variable is NULL, since the expression evaluates to "[ -z ]".
When using "[ ]", you really need to quote all values/variables. But, with the double-brackets, the test is a shell builtin. So nothing needs to be quoted, since it is not evaluated prior to being tested. Plus, you will save dozens of milliseconds by avoiding an external program.
Using the double-bracket with && is my favorite way of doing a simple if/then:
which is *essentially* the same as
I say "essentially" because the if/then executes the TRUE or the FALSE clause, never both. The other form can run both if the command after the && fails:
This will always print "not equal" since "ehco" is not a command and fails.
You can also do compounding:
but don't try to get too clever. A 50-line conditional statement using amperstands and braces is harder to read then plain old if/then/else.
Note that the amperstand can be used after any ordinary command:
Thanks a bunch for the explanation!
Now I can save hundreds of milliseconds in my scripts
I had some idea that the quoting rules were different, but wasn't clear about exactly what it meant in practical use. And man bash isn't very helpful, or just too much text for me...
Now I can save hundreds of milliseconds in my scripts
That can amount to an awful lot of time if you do it inside a deeply-nested loop. Suppose you execute the loop surrounding it 100.000 times: 100ms times 100.000 are 10.000 seconds, which are ~3 hours - not bad, yes?
Hello Experts
My SAP application is running in IBM AIX. Everyday my application generate some files in the below path as below.
root@sedcaspm0502: pwd
/interfaces/RFTS/B11/archive
root@sedcaspm0502: ls -lrt
-rw-r r 1 ppgadm sapsys 1039445 May 08 01:20... (1 Reply)
Hi All,
I am connecting from ServerA(Unix) to ServerB (AIX). Copying a Database dump file from A to B. On B i need to import that dump file.
I have used the following code to do this operation but ended up with error
Pseudo-terminal will not be allocated because stdin is not a terminal.... (2 Replies)
Hi ,
Good Morning every one !!!
I am very new to this forum and new to Shell Script as well , hope some script Guru's will help me .
I have a requirment to write a shell script . The requirment is like this . There are couple of shell scripts scheduled in the Crontab (some scripts run... (5 Replies)
Hi,
I'm trying to write a for loop to run through a list of servers and for each server copy a file to a backup file. But I can't seem to get it to run through my server list. It work for individual servers, please see below.
#!/bin/ksh
SSH_USERID=khcuser
webservers="server1 server2"
... (2 Replies)
hi all i want help to write the script thatti check rmt drive serial number if the same in two site Production and HA, the recomended like the follwing:
The : AIX script to set up tape devices on OS to be identical on both nodes
- define a rule, according to the renaming of the tape... (4 Replies)
Hello, I am trying to get the following Lawson command to work in an AIX script for a developer and I'm stumped, the Admin for this server is on vacation and I have very limited AIX scripting knowledge, I cannot seem to get this to work no matter what I try...
lawcmp test900 ap HM500
This is... (1 Reply)
Hi!
I have made a simple script for writing the following line on a file (file.txt):
list= 1 2 3
and thr script looks like this:
N=3
ll=(1 2 3)
echo -n "list= ">> file.txt
j=0
while ; do
echo -n ${ll}" ">> file.txt
let j++
done
The code works fine on Linux,... (3 Replies)
Dear All,
What points should i keep in mind while migrating scripts from HP-UX to AIX.
Are there any notes available for this?
cheers,
vishal (1 Reply)
Hello all,
I have a few questions regarding a UNIX script I've been asked to write (even though I barely know UNIX!).
I would like to write a script, that when run, will copy a file from one directory to another, copy and rename the same file with a datestamp to an archive directory, and them... (10 Replies)
Hello!
I need to run a script from the root user as the other user. I know that I can issue the following command:
su - user_name -c "/path_to_script/script_name.sh"
But there is a small problem with the above command. I must export a environment variable before I run the script. In the... (1 Reply)