I want to use an argument in the function I created in my .profile file.
I want to ask for input if no argument is given, otherwise set a variable to $1.
When I check $1 to see if it is empty, I get the following error:
sh[7]: 1: Parameter not set.
From the following line:
if [ ! -n "$1" ]; then
I'm using sh not bash.
EDIT: Ok, here is the first line of code until the end of the if statement:
HOST=`hostname`
cd /opt/dirpath
ll *.sto
if [ x"$1" = x ]; then
# Ask for input
echo "File: \c"; read outFile
else
outFile=$1
fi
I'm editing someone else's code to work with or without arguments.
if [ "x$1" = "x" ]; then ...there is no parameter[[ ... ]]construct is abashextension, you need to useif [ x"$1" = x ]instead.set -e?$1is the parameter. The error message says so. It says:[LINENO]: PARAM_NAME: DEFAULT ERROR MESSAGE.. Try it. Try:unset my_var_name; echo "${my_var_name?"My error message."}". And to test if a var is set or unset just do[ -z "${var+.}" ]