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,287 questions
0
votes
0
answers
38
views
pgrep executable matching specific (current) user only
In a code review on Final look at my Lightshot print screen Linux handler POSIX shell script, specifically in this short answer, it has been pointed out to me, that if there are multiple X servers ...
0
votes
0
answers
39
views
User can't execute a shell script based on shebang but ok when interpreter directly invoked [duplicate]
Context
I have a system user caddy and a shell script placed under /run/caddy/caddy-cert-obtained-wrapper.sh.
/run and /run/caddy are owned by root:root with permissions 0755.
caddy-cert-obtained-...
-2
votes
2
answers
96
views
Unix folder has file named "-f". Standard `/bin/bash` tools do not recognized this (can not `rm`, `cat`, nor `stat` this). What to do? [duplicate]
Welcome to Termux
Docs: https://doc.termux.com
Community: https://community.termux.com
Working with packages:
- Search: pkg search <query>
- Install: pkg install <package>
- ...
2
votes
1
answer
601
views
What is the purpose of using && at the end of a sh script line?
I have seen code like this in a /bin/sh script:
repo_files=$(git ls-files) &&
There is no line continuation. What is the purpose of && at the end of a line like this? Can the '...
-4
votes
1
answer
219
views
How to redirect command output to a file if the command itself contains redirection
In the below shell script I'm executing the some command cmd remotely where in the command output is redirected to some file cmd_log. I'm getting the desired result as long as the command cmd itself ...
7
votes
3
answers
907
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 ...
5
votes
1
answer
244
views
How to wait for subshells to finish from the outer shell?
If do this on my bash terminal:
(
(sleep 0.5 && echo 'first command, second result' &);
(echo 'second command, first result' &);
)
then I see:
second command, first result
...
7
votes
1
answer
260
views
Newlines in environment variable names under POSIX sh
This question asks how to get a list of environment variable names in POSIX sh. The top answer suggests invoking awk via the shell, but gives this caveat:
The output is ambiguous if the name of an ...
4
votes
3
answers
508
views
Shell (.exp) script only sending 1 of 2 files
I have a bash shell script that runs via cron. The script looks for 1 of 6 possible (data) files in a directory. If 1 or more of these files is found, a new (control) file is created for each data ...
3
votes
2
answers
138
views
Localising variables in /bin/sh functions
POSIX defines shell functions as:
fname ( ) compound-command [io-redirect ...]
The compound-command is further defined as either:
( compound-list )
{ compound-list ; }
In particular POSIX notes for ...
11
votes
5
answers
1k
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 ...
0
votes
1
answer
51
views
Storing the iterations of the Receiver (or node) number and RSSI value into a file
I'm quite new to Linux. Recently, I've been able to create a bash script that allows me to obtain the RSSI of the receivers (or node) with a running iteration. How can I store these results in an text ...
0
votes
1
answer
783
views
grep behaviour is different when run using bash -c '...'
I met an interesting issue while working with this code from Stack Overflow: tripleee's answer on "How to check if a file contains only zeros in a Linux shell?"
Why does the same bash code ...
1
vote
0
answers
444
views
Unable to change default shell to bash on new cachyOS installation [closed]
Updated
Just booted the PC and now it works.
>echo $SHELL
/bin/bash
>
Very strange. so loggin out and back in was not enough.
So should I close this question then?
Just installed new CachyOS ...
6
votes
1
answer
490
views
`rsync`: trailing slash vs wildcard
Suppose I want to sync the contents of a directory (source_dir) using rsync without creating a directory named source_dir in the target directory.
I can do this using rsync source_dir/ target_dir or ...