In my script, I transform data to a more readable format. But I am having an issue. If no arguments are typed, just the script, I want it to come back "Please enter a filename" which I have done. But for some reason, it will not display that when tested. I did it by telling the system if argument is greater than 0, execute, otherwise, echo the message.
*I am not looking for advice on the substitution code. For specific reasons, it cannot be changed, so please do not give advice on that piece.
for myvar
do
if [ $# -gt 0 ]
then
if [ -e "$myvar" ]
then :
else
echo "$myvar cannot be found."
exit
fi
echo "This is the filname:" $myvar
cut -f1 -d, $myvar > social_security
cut -f2 -d, $myvar > last_name
cut -f3 -d, $myvar > first_name
sed 's/^ *//' last_name > last_name_draft
sed 's/^ *//' first_name > first_name_final
sed 's/-//' social_security > social_security_draft
sed 's/-//' social_security_draft > social_security_final
sed 's/$/:/' last_name_draft > last_name_final
paste -d\ first_name_final last_name_final social_security_final > final_draft
sed '1d' final_draft > final
cat final
echo -en '\n'
else
echo "Please enter a filename."
fi
done