Questions tagged [bash]
Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.
27,294 questions
-1
votes
1
answer
62
views
Is there a way to continue script execution if ping fails due to nonexistent interface?
I am trying to execute a script that loops through a set list of interfaces and pings a known destination.
It is possible that one of the interfaces may not always be available. Right now, script ...
5
votes
1
answer
228
views
Msys2 bash rejects empty subexpression in regular expression
I'm running a reasonably up-to-date Msys2:
$ uname -a; bash -version
MSYS_NT-10.0-26100 md2syz7c 3.6.6-2369286a.x86_64 2026-01-14 12:29 UTC x86_64 Msys
GNU bash, version 5.3.9(1)-release (x86_64-pc-...
0
votes
2
answers
169
views
Bash - How to securely erase a password from memory which is displayed whilst being typed
I'm looking at ways to handle secure password input during scripts but where the password is displayed as it is typed (for multiple reasons). I'm currently using read pwd to read in the password, ...
1
vote
1
answer
81
views
List all members of a group, where the group is primary?
How can I simply and easily display all members of a group where the group is primary for the users?
Most posts show getent group <groupname>, but that only shows me the group name and the group ...
3
votes
3
answers
402
views
Selective writing of selected lines from the ping command to a file
Currently in Debian I use such a command to save the ping history to a file (with the exact time):
ping -c 3600 1.1.1.1 | ts '[%F %T]' | tee -a /home/user/testping.txt
How to:
Have all ping responses ...
8
votes
2
answers
405
views
Save and restore bash RETURN traps within functions
I have multiple bash functions that generate temporary files and the naive me started to create RETURN traps within them to clean those files up, just to learn that nesting traps is really tricky...
...
1
vote
2
answers
85
views
Dealing with stale mounts in shell scripts
I'm writing a bash script that archives logs from a folder where various servers dump their logs. From there, it moves them to one of three OneDrive mounts that are mounted with rclone (which I think ...
0
votes
2
answers
69
views
Issue with looping through an array/list of hostnames [duplicate]
I want to execute an Ansible playbook over a couple of servers and see some issues with ssh connectivity on the way (mismatches in my local known_hosts I am guessing).
I want to solve this by ...
1
vote
4
answers
80
views
Inserting a multi line variable with other variables in it into a file at a specific line number with sed
I'm trying to write a Bash script to automatically add the configuration of the WordPress WP Offload Media plugin to the wp-config.php file, asking for the Amazon Web Services (AWS) credentials ...
0
votes
1
answer
64
views
Why `date -d` doesn't respond to change of `LC_TIME` variable
In KDE System Settings locale is UK apart from keyboard layout, which is Italian.
For some reason, this is the output of the locale command:
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
...
-3
votes
3
answers
95
views
problem with looping through 2 arrays in bash
I have a file like this
> cat /tmp/lists
# user0 db0
# user1 db1
# user2 db2
I want to extract two arrays (column 2, column 3) from this, so I end up with roles=...
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 ...
-3
votes
2
answers
179
views
Double pass processing of stdin with bash
Assume that, for whatever reason, a bash script must go through stdin once and then go through that very same input again. For example, a script might need to know the number of lines that stdin input ...
1
vote
2
answers
248
views
Calling a function through command substitution
When you have a function f defined in a Bash script, you can call it using $(f). However, this creates a subshell in which the function is called.
Consider this example:
#!/usr/bin/bash
f() {
echo ...
-2
votes
2
answers
141
views
Strange $$ behavior in bash
I was trying to craft a script that produces the location of the local bash binary from a variety of (Linux) environments, assuming existence of standard shell /bin/sh and that /usr/bin/env bash is ...