I need to port a short script from bash
to dash
(i.e. sh
under Debian 10). It contains the following line:
chown root:www-data /etc/nginx/conf.d && chmod 775 $_
This now fails because $_
held the previous command’s last argument (i.e. /etc/nginx/conf.d
) with bash
but now holds a different value with non-interactive dash
. As another case in point, outputs from bash -c 'echo 1 2 && echo $_'
and dash -c 'echo 1 2 && echo $_'
also differ.
What is a typical way for forming "concise" statements of the above type in dash
(without resorting to more specialized commands, such as install
)?
2
Answers
Just write a function.
And replace the line with the following.
Just define an explicit variable to hold the directory name.
$_
is intended as an interactive shortcut. A script, written with the help of an editor, doesn’t really need such shortcuts.