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,272 questions
0
votes
1
answer
35
views
How to move the cursor to an embedded newline on the bash command line? [duplicate]
I have just pasted a line into the bash shell.
It contains embedded newlines.
CTRL+a gets me to https at the start.
CTRL+e gets me to 7d87 at the end.
How can I move around from line 1 to 2 to 3 ...
2
votes
2
answers
113
views
Bash/Dash - Catching the error when calling set
I'm writing a script and I'd like to use set -o pipefail on shells that support it. Dash does not support that option. Usually, || true lets me swallow errors, but not in case of set:
> podman run ...
0
votes
1
answer
32
views
Cancel just second command of bash logical AND operator [duplicate]
It often happens that I have some long task running, like compiling a program, running tests or copying large archives. Once I am done with whatever else I was doing, I want to leave the computer ...
5
votes
2
answers
831
views
POSIX sh alternative to using [[ ... ]] in Bash
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
1
answer
54
views
disable bash job control warning "job specification requires leading `%'"?
I just rebooted one of my systems for the first time in several months, restarted tmux and my usual set of bash shells for tailing various log files, and noticed that running fg n (i.e. fg followed by ...
2
votes
3
answers
184
views
bash syntax: what does '[@]+' mean? [duplicate]
I have a script that parses command line arguments.
The intro to the loop to iterate over the argument array looks like this:
for arg in ${args[@]+"${args[@]}"}; do
Can someone explain this ...
3
votes
6
answers
394
views
How can I use sed to chain append lines from a text file, add it as a suffix to the text on the same lines numbers on another file, and so on?
I've tried using sed for this. I've tried putting the lines of interest in variables as well.
I have two examples I want to achieve for now. Lets say I have thousands of urls in a file called links....
0
votes
0
answers
57
views
how to convert hex memory dump to Docsis config file?
Hex memory dump is Docsis config file. Is it possible to convert this hex dump info valid Docsis config file? Preferably, using Perl and DOCSIS::ConfigFile module. (or Python scripts, python-docsis). ...
3
votes
3
answers
904
views
How do I ensure a bash script argument is a specific value?
The following script is supposed to check $1 and see if it is a specific value. It only works when one Bash [[... =~ ...]] regex check is passed in an if statement.
The error is: When more than one ...
4
votes
1
answer
198
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&...
1
vote
1
answer
44
views
White spacing is causing variable to not contain all text in result
Disclaimer: I am brand new to bash
I'm building a dialog box and trying to get some Docker commands to populate results.
I am using this to return a result, which works for the most part.
result=($(...
0
votes
2
answers
145
views
Process sed capture group with a bash function before replacement: "sh: 1: <bash function>: not found"
So, I was playing around with this answer, when I found that neither
printf_stdin () {
read input
printf "$input"
}
sed "/lorem ipsum foobar/ {
s/'/'\"'\"'/g
s/\...
0
votes
1
answer
41
views
`xargs sh -c` not picking up last argument (vs `for i in $(...)`) [duplicate]
I just wanted to build a simple bash script that inverted a 'hex color code' (made up of 3 pairs of 2-digit hexadecimal numbers, in the format #RRGGBB). In my first code block I attempt to perform ...
2
votes
1
answer
36
views
Shell bracket list wildcard doesn't work with variable [duplicate]
The following works:
ls {000/487,000/488,000/489,000/490,000/491,000/492}
...many files being listed
But this doesn't. Why ?
LIST=000/487,000/488,000/489,000/490,000/491,000/492
ls {$LIST}
ls: cannot ...
11
votes
1
answer
1k
views
Is there any difference between [[ -n $1 ]] and [[ $1 ]] in bash?
The test [[ -n $1 ]] yields True if the length of string is non-zero.
But I've seen elsewhere and have tried using just [[ $1 ]] without the primary -n and it seems to have the same effect.
Is there ...