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.
26,536 questions
2
votes
4
answers
80
views
Using curlybraces to process colon seperated variables
if we do:
VAR=100:200:300:400
We can do:
echo ${VAR%%:*}
100
and
echo ${VAR##*:}
400
Are there any equivalents I could use to get the values of 200 and 300?
For instance a way to get only what's ...
-2
votes
1
answer
55
views
Creating in Linux files in GB or MB range by various size by read a file
In Linux with Bash, there is the File numbers_in_one_line.
In this file there is only one line with several numbers, all separated by spaces.
These numbers are the value in bytes for creating files ...
0
votes
2
answers
54
views
Counting unique IP addresses per hour in existing log files
I am trying to determine the number of unique web visitors to my website each hour. The log files (access*.log) contain many lines looking similar to this.
192.168.211.85 - - [29/Sep/2024:10:17:02 -...
0
votes
1
answer
38
views
Where to set XDG_RUNTIME_DIR per user?
So I ran into the following interesting problem:
I tried to define XDG_RUNTIME_DIR in my .bashrc as follows:
export XDG_RUNTIME_DIR=$MY_HOME/.local/share
After doing this I noticed my pactl cli ...
0
votes
1
answer
63
views
bash - list of breaking change
I know bash tries very hard to keep new versions compatible with previous ones.
However they sometime introduced (minor, but still) breaking changes:
for exemple when we could no longer have : { foo }...
2
votes
1
answer
52
views
Why can't I have a single quote in a bash associative array index when testing with `test -v` [duplicate]
When I run the following code
declare -A X # get an associative array
index="a'b" # a somewhat weird index
X[$index]="this is set"
echo "<<${X[$index]}>>"
if ...
12
votes
1
answer
2k
views
Why does cd '' succeed in bash?
Maybe I'm missing it, but I don't find it documented that cd '' should succeed. Since there is no directory with the name '', it seems obvious that it should fail. For example,
mydir=
cd -- "$...
0
votes
2
answers
80
views
How does `*\ *` work in bash?
There is an answer from SuperUser, which renames filenames containing whitespace:
for f in *\ *; do mv "$f" "${f// /_}"; done
The part I don't understand is *\ *.
The author wrote ...
2
votes
1
answer
183
views
Using Here-Document as password Input for ssh
First, I do know this is a security risk. I do know about ssh keys and sshpass. This belongs to a fun project.
I wondered if a bash Here-Document could be used as a password input for ssh.
I ...
-3
votes
1
answer
96
views
bash -n is a not documented in manpages or info documents [closed]
Even though bash -n is a valid and widely used option, some manpages don't clearly document it in the bash options section, even though it is implemented. It's also not in the GNU Bash Reference ...
5
votes
6
answers
1k
views
Why can't I merge folders by renaming one of them?
Try to run this
mv -- "foldername...__" "foldername..."
This will move folder foldername...__ under the folder foldername... instead of renaming it. Why?
Note that foldername... ...
0
votes
1
answer
84
views
How to create splittet random files and join them with dmsetup
In Linux in Bash, there is a script, a part of the script is this
while true ; do
echo
awk -v x=$(<"$TEMPDIR"size_container_in_byte) -v n=$(<"$TEMPDIR"parts) 'BEGIN{...
0
votes
1
answer
103
views
How to compare output of a program with a reference value in a shell script?
I have my own implementation of a Redis server which I'd like to test through a shell script.
The general idea is to feed it with some commands through nc, and since nc prints the output of my program ...
4
votes
1
answer
162
views
Run in background avoiding any job control message from the shell [duplicate]
Lets define a shell function (here the shell is Bash) and test it
$ s () { xterm -e sleep 5 & }
$ s
[1] 307926
$
[1]+ Done xterm -e sleep 5
$
With my specific meaning of ...
2
votes
2
answers
93
views
Merging values from 2 YAML files in bash
A bash command:
$(System.DefaultWorkingDirectory)/yq_linux_amd64 '. *= load("${{ parameters.HELM_CHART_PATH }}/values/DEV/${{ parameters.COMPONENT }}.yaml")' ${{ parameters.HELM_CHART_PATH }}...