Hot answers tagged

1 vote
Accepted

How do I use xargs to pass arguments as $1, $2, $3, ... to an inline script called with sh -c?

First of all, you don't do sh -c "echo $1 - $2 - $3" because the double-quotes will cause your current shell to expand $1, $2 and $3. Even if you managed to set these in the current shell ...
1 vote
Accepted

Bash command to cd into a directory I know exists but don't know the name of

After extraction, count the number of items in the output directory: declare -a items=("$outdir"/*) (You probably can assume that your users won't give you .dotfiles, I guess?) If there's ...
  • 386k
1 vote
Accepted

Error when trying to execute command with sudo su - user -- command

You don't actually need su in the command at all (what your sudo su - user does is to use sudo to jump to root with full privileges, and then use su to downgrade to the account called user. You might ...
  • 2,072
1 vote

Error when trying to execute command with sudo su - user -- command

sudo su - user will load the profile startup files, which probably set the PATH to the direct command. When you use -c, the direct command can't be found. One solutions would be to specify the full ...
  • 351
1 vote
Accepted

Execute EOF command remotely in one line

You're asking about one-line Here Documents. This is possible using Here Strings. For example : command >"$HOME/myfile" <<<'mytext' This will send the string mytext to command ...
  • 416k
1 vote

Do command line applications generally close between user commands?

Generally, yes. Every new command run from the shell is a whole new process that is spawned or fork/exec'd (except for those built-in to the shell), and whenever you return to the shell's prompt, this ...
  • 386k

Only top scored, non community-wiki answers of a minimum length are eligible