I need to write an argument to a file in a Bash script, so I'm doing something like this,
echo "Argument is: $1" >> file
The problem is that if there's a tilde (~) in the argument I don't want it expanded to the home directory. So if the user passed ~/bin as an argument to the script, it would get written as ~/bin and not /home/user/bin. How do I do this?
I assume your program is started as:
$ your_prog ~/foo
The argument is translated before your program is even started, so there's nothing you can do to prevent it other than educating the user to quote appropriately if the expansion is not desired:
$ your_prog "~/foo"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With