Home > Back-end >  Stop tilde expansion in bash script arguments
Stop tilde expansion in bash script arguments

Time:02-25

Consider this tiny script:

# script.sh
echo $@

If I call it like this ./script.sh ~/docs, I get /home/me/docs as output. However, I need it to echo ~/docs. How can I achieve that?

CodePudding user response:

It's not under the script's control. It's up to the user. They must quote the tilde to prevent it from being expanded. Options include:

./script.sh \~/docs
./script.sh '~/docs'
./script.sh "~"/docs
  • Related