Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How clear positional parameter

Status
Not open for further replies.

uzel

MIS
Oct 17, 2002
5
FR
Hello,

I would like done the following functionality.
At launching time
1) If argument is added to the script-name, argument is used as variable via $1 positional parameter.
2) If no argument is added to the script-name, argument is prompted and read via read v1? command.

It does not work because if option 1) is used first $1 positional parameter is always present, so case 2 appears only if "" is passed as argument

shell ksh

f1=$1
echo "v1: $1"
if [ -z "$f1" ]
then
read f1?"Enter filename: "
echo "file: $f1"
read f2?"output filename : "
else
f2=$2
fi

unix > . rvr*h aaa
v1: aaa
unix > . rvr*h
v1: aaa
unix > echo $1
aaa
unix >
unix > . rvr*h ""
v1:
Enter filename: bb
file: bb
output filename :
unix > echo $1

Do you have any idea to solve it?

Thanks in advance,
 
Hi

As far as I understand it, I would do it like this :
Code:
[ "$1" ] && f1="$1" || read f1?"Enter filename: "
echo "in file: $f1"

[ "$2" ] && f2="$2" || read f2?"output filename : "
echo "out file: $f2"

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top