Questions tagged [shell]
The shell is Unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.
12,284 questions
3
votes
1
answer
161
views
Handling of Single Quotes inside a Here-Document
According to the Shell Command Language Specification: "2.7.4 Here-Document":
Any <backslash> characters in the input shall behave as the <backslash> inside double-quotes (see 2....
7
votes
4
answers
805
views
Are there filesystem "tricks" that may make `rm -rf /dir/*` accidentally delete things outside of `/dir`?
I'm creating a script that runs as root, which needs to run some code (network download and archive unpacking code to be specific) that has some unavoidable attack surface. To lower the damage if this ...
0
votes
2
answers
62
views
Why is `systemctl show-environment --user` different from the environment available to systemd service when running as the same user
While I was trying to write a service that uses a user's environment variables (loaded via .profile), I noticed that systemctl show-environment --user (run as e.g. myuser) would show me a certain set ...
5
votes
3
answers
1k
views
POSIX sh alternative for bash's regexp matching
I am using this code to parse the first argument passed to my script. It error handles and it works just the way I want it:
if [ -z "$action" ]; then
printf "[${c_RED}ERROR${c_RESET}...
0
votes
2
answers
81
views
How can I read a single key press from a user if it's either the Escape key or a function key?
I'm writing a shell script that's aimed to be as portable and POSIX-compatible as possible, so usage of bash-only commands or high-level input libraries is undesirable.
I'm looking for a way to read a ...
11
votes
6
answers
2k
views
Using `find` to find a file in PATH
I would like to be able to search all my $PATH for files matching a given pattern.
For example, if my PATH is /usr/local/bin:/usr/bin:/bin and there's a /usr/local/bin/gcc-4 and a /usr/bin/gcc-12, I ...
14
votes
2
answers
1k
views
Why do shell control statement have that syntax (semicolon/newline+then/do)
I of course realize the need to have something that separates the condition to the actual commands to be executed under the control statement, but why were it chosen to use both semicolon and a ...
10
votes
4
answers
997
views
With `#!/bin/sh`, what is the closest to `;;&` (`bash`'s fallthrough)?
Without ;;&, /bin/sh gives Syntax error: ")" unexpected (expecting ";;").
;;& triggers shellcheck's ^-- SC2127 (error): To use cases with ;;&, specify #!/usr/bin/env ...
1636
votes
10
answers
548k
views
What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?
I think these terms almost refer to the same thing, when used loosely:
terminal
shell
tty
console
What exactly does each of these terms refer to?
4
votes
1
answer
263
views
Choice of field separator affects sort's ordering
Suppose we have a script named test_sort in our $PATH with the following contents:
#!/bin/bash
function echo_text () {
printf -- "%s\n" "$fc$oc$fs$lc"
printf -- "%s\n&...
663
votes
12
answers
1.4m
views
How to append multiple lines to a file
I am writing a bash script to look for a file if it doesn't exist then create it and append this to it:
Host localhost
ForwardAgent yes
So "line then new line 'tab' then text" I think its a ...
538
votes
22
answers
285k
views
Get exit status of process that's piped to another
I have two processes foo and bar, connected with a pipe:
$ foo | bar
bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
595
votes
7
answers
320k
views
What is the difference between the Bash operators [[ vs [ vs ( vs ((?
I am a little bit confused on what do these operators do differently when used in bash (brackets, double brackets, parenthesis and double parenthesis).
[[ , [ , ( , ((
I have seen people use them on ...
0
votes
1
answer
121
views
LF file manager : how to go back to $OLDPWD?
What do I want :
On the file manager lf, we can bind some keyboard shortcuts to do either a lf command with :, or a shell command with $, !, or other symbols.
According to the documentation, there is ...
0
votes
0
answers
65
views
the shell escape security issue with the container
I have develop a latex render engine that run with kubernetes container pod, now I want to supprot the minted package that need to open the shell escape feature.
use std::process::Command;
use std::...