I have to use ksh on HP-UX for some scripting.
I usually use "set -e -u" in scripts to stop if errors occur or a typo is in a variable name.
Now I try to use "$@" to pass the arguments unchanged to another function, which works without problems - unless I try to call the script without arguments... In that case $@ is considered undefined and the -u kills the script, instead of calling the function without arguments, as planned.
Is there any nice way to solve that problem without +u or duplicating parts of the code?
@mimi: Those are two different ksh, which do not share the same bugs.
@shamrock: I was thinking about that approach, too, but it duplicates the code (which is a bit more complex than "f") and even more important makes the code much less readable.
@Perderabo: Thanks a lot, guess something like "${@+$@}" should be exactly the right thing to fix the issue.
If you needed [/icode]"$@"[icode] then you will still need internal quotes like this: ${1+"$@"}. If no quotes are needed then a simple $@ should suffice. As far as replacing the 1 with @, as in ${@+"$@"}, that is interesting. It seems to work as well as what I suggested, but no better. Are you worried about a missing $1? Both constructs handle it well. ${1+"$@"} is very slightly less work for the shell than ${@+"$@"} but the real avantage that ${1+"$@"} might have is that it has become standard. I first saw used in the late 80's so it has been around for awhile. But if you see some value to ${@+"$@"} please let me know what I'm missing.
Anyway I'm glad you posted the question. I still use ${1+"$@"} in my ksh scripts for portability to early versions of ksh. When people tell me that the practice is superfluous with ksh, I will refer them to this thread.
Well I liked @ instead of 1, because it exactly maps the problem of the undefined $@ and looks somewhat more readable to me. The result should be exactly the same.
Regarding "${@+$@}" vs. ${@+"$@"}, yes, the second one is probably the better one.
At least under bash they do exactly the same, but that ksh might generate an empty argument in the first case. (I had no chance to try out, yet.)
BTW, is it possible to assign the content of $@ (or ${@+"$@"}) to another variable?
If I do something like this:
the assigned variables have no longer any idea about the correct number of argument.
I've tried to find a solution to this, but I"m stumped.
OS - RH Linux 5.9
I have a bash script <myProgram.sh> that gets executed manually and creates a small response file. I'm trying to automate the running of this script.
When myProgram.sh runs, it prompts the user to enter 2 pieces of... (13 Replies)
myscript.sh
#!/bin/bash
ARGA=$1
if ; then
echo "${ARGA}:Confirmed"
else
echo "${ARGA}:Unconfirmed"
fi
when I run the above script from the command line, i run it as:
./myscript.sh jsmith
now some times, i need to runn it this way: (8 Replies)
hi,
Is it possible to pass arguments to a sftp script and use those arguments in the program?
for example
sftp_script
FILENAME=$1
#!/usr/bin/expect
spawn /usr/bin/sftp abc@ftp.abc.com
expect "abc@ftp.abc.com's password:"
send "pass\r"
expect "sftp>"
send "mput $FILENAME\r"... (9 Replies)
Hello,
Please, how can i pass arguments to my lib.so ? my lib.so is written in c and i need some arguments in the code ..
LD_PRELOAD=lib.so ./program
Thank you. (1 Reply)
Hi,
I want to run a target of makfile using script by passing different arguments to it again n again. I i need to grep certain things from the log file.
eg
make abc KAB=8 BAC=8 >& KAB_BAC.log
grep "timeA" KAB_BAC.log
grep "timeB" KAB_BAC.log
(i want to store the difference of the two time... (0 Replies)
Hey guys,
I have an interactive script that is quite critical to our production environmentl thus updating it to run non-interactively is not an option.
The script takes a varying number of arguments, which it ques untill user confirm end of data entry
e.g of user input :
1
2
y ... (3 Replies)
Hi,
I have a my script here--
print "The Perl Script does the User health check and system health check...\n";
print "---------------------------------------------------------------------\n";
# use strict;
my($OS);
$OS = $^O;
# need to test @ARGV before GetOptions shifts it
if (@ARGV... (1 Reply)
Hi,
I have a shell script called ftp.sh which is running continously in background.
I tried passing arguments to this script but it did not worked out.
Below is ftp.sh script. Please help me
case $param in
start) sleep_func "300"
echo "!ksh $scr_ddir/ftp.sh... (1 Reply)
Dude,
I want to kill a process, but the processid is in a text file. I have to read the text file for the process id and pass it as parameter to the kill command.
Example
$ cat prcid.txt
18650
I want to pass the value 18650 as a process id to kill command.
$ kill -9 <value read from... (4 Replies)