I have some bash code that i am running in a zsh shell on macos.
Code seems to work fine when i run in the shell, but when i run the file from my path, it only brings back the initial and not the initial+surname, any help most appreciated.
user="Steve Thomas"
dbuser=$user
initial="${user%"${user#?}"}"
userie=( $( echo $dbuser | cut -d' ' -f1- ) )
userlastname=${userie[2]}
fulluser="${initial}${userlastname}"
echo $fulluser
when run in shell i get what is expected
SThomas
and when i run as file.sh from path i get..
S
Not sure what i am doing wrong here, please advise.
file.sh, the #! line determines, which shell is used, but there is no such line in your script. Also you tag the question as bash and zsh, and we don't know what shell is processing your code. Please make up your mind first what programming language (= shell) you are using, and then write the program in it.