I can't use environment variables with chmod command. Is there any workaround to run this?
The way I'm trying to run in a sh file
export PEM_FILE="~/.ssh/xxx.pem"
chmod 400 $PEM_FILE
Output
chmod: ~/.ssh/xxx.pem: No such file or directory
However, it work perfectly fine without the variable like this: chmod 400 ~/.ssh/xxx.pem
P.S: I am on macOS. Kindly let me know if this works fine in windows or linux.
Thanks!
export PEM_FILE=~/.ssh/xxx.pem
(orPEM=$HOME/.ssh/xxx.pem; export PEM
, which will work in all bourne-like shells). No, the quotes aren't needed withexport PEM=...
. But they are needed withchmod 400 "$PEM_FILE"
. – Nov 12 '21 at 00:29