cqfd helps running commands inside the Docker container configured for your project, keeping the user and working directory the same inside the container
GNU General Public License v3.0
64
stars
31
forks
source link
Use $1 instead of "$@" and reference as command string #114
TL;DR; The entry-point shell script takes a single argument from the function docker_run() as a command string, but it uses "$@". Therefore, $1 is enough and it should be used instead to avoid confusion.
This uses $1 instead of "$@" and updates the reference of command to command string for clarififcation purpose (as in sh(1)).
According to sh(1):
command_string
A string that shall be interpreted by the shell as one or more
commands, as if the string were the argument to the system()
function defined in the System Interfaces volume of
POSIX.1‐2017. If the command_string operand is an empty string,
sh shall exit with a zero exit status.
Here starts the long story.
cqfd uses a shell script as docker-run entry-point. It adds the user in the container and it runs the command string given in parameter as the user using either sudo or su.
The su command runs the command via a shell with an internal added -c argument:
su user -c command_string [command_name argument...]
Where command_name is execve()'s argv[0], and argument are argv[1]... i.e. like sh(1):
[root@archlinux gportay]# su gportay -c 'echo command_name=$0, arguments=$*, argument_count=$#' zero one two three
command_name=zero, arguments=one two three, argument_count=3
The sudo command runs a command like execve(), without the possibility to set argv[0]:
sudo -u user command_file [argument...]
Where command_name is execve()'s path and argv[0], and argument are argv[1]...
Example:
[root@archlinux gportay]# sudo -u gportay /bin/sh -c 'echo command_name=$0, arguments=$*, argument_count=$#' zero one two three
command_name=zero, arguments=one two three, argument_count=3
The sudo backend runs the command given in parameter through /bin/sh -c for compatibility purpose with the su backend since both backends run the command differently: one like execve(), one like system().
TL;DR; The entry-point shell script takes a single argument from the function docker_run() as a command string, but it uses "$@". Therefore, $1 is enough and it should be used instead to avoid confusion.
This uses $1 instead of "$@" and updates the reference of command to command string for clarififcation purpose (as in sh(1)).
According to sh(1):
Here starts the long story.
cqfd uses a shell script as docker-run entry-point. It adds the user in the container and it runs the command string given in parameter as the user using either sudo or su.
The su command runs the command via a shell with an internal added -c argument:
Where command_name is execve()'s argv[0], and argument are argv[1]... i.e. like sh(1):
Example:
The sudo command runs a command like execve(), without the possibility to set argv[0]:
Where command_name is execve()'s path and argv[0], and argument are argv[1]...
Example:
The sudo backend runs the command given in parameter through /bin/sh -c for compatibility purpose with the su backend since both backends run the command differently: one like execve(), one like system().
[jo: adjust docstrings and help]