156,668 questions
Score of 6
5 answers
224 views
Remove multiple occurrences of similar lines except the last
I have a file where a pattern repeats a various number of times between lines that are relevant. I want to keep only the last of the lines that repeat in each occurrence of the repetition. This is ...
Score of 4
2 answers
103 views
Declare with global and export does not work for sub shell
This is using bash 5.2 on Ubuntu 24.04.
I have the following two scripts.
init.sh:
#!/bin/bash
function init_env() {
# Setup some critical variables
declare -agrx BIRD_LIST=("albatross&...
Score of -3
1 answer
120 views
What does 'echo "\" ' do in bash, and why does exiting it exit the parent process? [closed]
What does echo "\" do?
Why is it multiline? Does it somehow escape the newline character? When newline appears as part of the variable, it processes it.
Why do Ctrl-C and Ctrl-D exit the ...
Score of -3
1 answer
63 views
OpenCode Desktop Application Showing EPRM Error [closed]
When any model in OpenCode Desktop app tries to run any command in shell or terminal or bash, then it shows "EPRM" error. It cant run any commands or terminal.
Can anyone tell me what to do?
...
Score of 0
3 answers
150 views
Running sh or bash script commands from the bottom to the top
I have a bash script with n > 1 commands that looks as:
#!/bin/bash
cmd_1
cmd_2
...
cmd_n
Is there a way to run this script from the latest command to the first one without writing another ...
Score of 4
3 answers
137 views
Why do indices behave differently than setting to a variable in bash loops over arrays that contain quotes and spaces?
Let's say I have a bash array that looks like this:
samples=("one 1 uno" "two 2 dos" "three 3 tres")
I'm looping through this array, hoping that I will get three ...
Score of 2
1 answer
83 views
Nextflow Task-Finalizer unable to locate expected file saved in publishDir unless I copy to PWD
I have been porting a pipeline over to NextFlow that involves saving inter-process temporary files to a secondary directory for later access. I set publishDir to this temporary directory, and when I ...
Score of 0
0 answers
50 views
How to make bash's "read -p" show the prompt in an emacs shell buffer? [closed]
In bash, a read -p "This is the prompt > " will show the prompt to the user only if the user is at a terminal. I often use emacs shell buffers as terminals, but the prompts aren't shown. ...
Score of -3
0 answers
98 views
Sorting an array in bash on a numerical field [closed]
I want to tidy up my (onsite) backup and remove duplicated files.
The deletedfiles folders are created by rsync. Some have been zipped.
Searching for $file=IMG_8041.JPG
found=$(unzip -l $i | grep &...
Best practices
0
votes
5
replies
101
views
How can I redirect a here document and store it in a Bash variable?
I'm trying to write a few inline tables that will be stored in bash variables but I can't get stdin/stdout to redirect the right way when using read -d '' VAR to try storing them into variables. I ...
Score of 2
2 answers
144 views
Command options with parameters including spaces in variable [duplicate]
When I run the following bash script:
options="--nup 2x2 --column true --columnstrict true"
pdfjam inp.pdf '1-8' $options --offset '0mm 1mm' --outfile out.pdf
everything runs fine, and I ...
Score of 3
1 answer
113 views
How could this dash-style named function makes infinity calling in bash?
I can run code like this in bash
#: can works well:
#: (start a new bash)
foo_a () { echo a ; }
foo-a () { foo_a ; }
echo will out a:
foo_a
It works well.
These work well also:
#: can works well:
#: (...
Score of 0
1 answer
88 views
If clause doesn't work when getting result from an evaluation of a mongosh script [closed]
I have no idea why the code below doesn't work.
The if clause is never true, even if variable $cf1 is a true "yellow" or a true "white".
The true value becomes yellow if the ...
Advice
0
votes
5
replies
149
views
Count lines for each file in .tar.gz Archive
In my .tar.gz a number of txt-files are archived. I would like to count the number of lines for each one and report a list having the number besides the filename, f.e.
a.txt 88
b.txt 233
c.txt 101
I'...
Score of 3
2 answers
120 views
Mongosh --eval, braces and syntax errors
bash 5.1.8
mongosh 2.5.10
mongodb 8.2.9
This works:
$ mongosh HIFRRMGP --eval 'db.AuditLogCollection.countDocuments({})'
137
And this works:
$ mongosh HIFRRMGP --quiet
HIFRRMGP> db....