hi,
I want to implement some function to perform following task
if [ firstArgument is not provided ]; then
$TEXT = "Data_0"
else
$TEXT = $1
fi
if [ secondArgument is not provided]; then
$Lines = 45
else
$Lines = $2
fi
#!/bin/sh
#Default values
TEXT="Data_0"
Lines=45
if [ "$1" ]; then
[ "$1" -eq 0 ] >/dev/null 2>&1; x="$?"
if [ "$x" -lt 2 ]; then
echo "Arg is an integer, to be set to Lines"
Lines="$1"
else
echo "Arg is not an integer, so, it's probably some text"
TEXT="$1"
fi
fi
Hi tukuyomi,
Thanks for the reply !
As I understood it would work. But I need to provide both argument together. But yeah ECHO would help in recalling as what argument should be text and what should be integer?
./script.sh text
./script.sh integer
./script.sh text integer
all three at the same time?
Or Am I confused as well? :s
Try this :
#!/bin/sh
#Define a function
intortext() {
[ "$1" ] || return 0
[ "$1" -eq 0 ] >/dev/null 2>&1; x="$?"
if [ "$x" -lt 2 ]; then
echo "Arg is an integer, to be set to Lines"
Lines="$1"
else
echo "Arg is not an integer, so, it's probably some text"
TEXT="$1"
fi
}
#Default values
TEXT="Data_0"
Lines=45
#main()
intortext "$1"
intortext "$2"