20

#!/bin/bash sleep 3 & sleep_pid=$! sleep 1 sleep 4 & wait "$sleep_pid" Putting that sleep 3 in the foreground would be equivalent to waiting for it to finish. I'm assuming this is what you want to do (or at least that this is the effect that you're looking for), and this is what the script above does. It does this by saving the PID of ...


20

You need to just enable job control in the shell with set -m #!/bin/bash set -m sleep 3 & # test sleep 1 # wait some sleep 4 & # run program under test jobs fg %1 quoting from bash manual: -m Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support it (see JOB CONTROL above). Background ...


19

This while [ "$choice" != "yes" && "$choice" != "no" ] does actually not work, because the && breaks the [ command. Use either of: while [ "$choice" != "yes" ] && [ "$choice" != "no" ] while [[ "$choice" != "yes" && "$...


12

A literal translation of While (choice.IsEmpty() || (!choice.equals("yes") && !choice.equals("no")) in POSIX sh syntax would look like: while [ -z "$choice" ] || { ! [ "$choice" = yes ] && ! [ "$choice" = no ] } do ... done For a closer match, you could use ksh93 which has ...


10

is there another way to test that You could use the standard case construct: case $choice in yes|no) false ;; esac which can be used even in the condition part of a while, though the construction may end up a bit confusing: while case $choice in yes|no) false ;; esac; do the same way as in Java? No


7

The reason is rather simple: Your continue statement instructs the shell to immediately skip execution to the next loop iteration. Unfortunately you thereby skip the ((COUNT++)) part, meaning then once COUNT reaches 5, it will never be incremented again, and the while condition never be met, so you are stuck in an endless loop from that point onward. If, as @...


7

Change the output field separator OFS to a null (empty) string and change $2 to _: $ awk -v OFS= '{ $2="_" }1' *.dat 20210101_NewYear'sDay 20210102_LaborDay 20210103_IndependenceDay


6

xargs is probably the worst POSIX utility when it comes to portability (and interface design). I would stay away from it. How about: <file.hex awk -v q="'" -v ORS= ' BEGIN{ for (i=0; i<256; i++) c[sprintf("%02x", i)] = sprintf("\\%o", i) } NR % 50 == 1 {print sep"printf "q; sep = q"\n"} {...


4

With the redirection on a new line, it applies to the empty command; to fix this, place it on the done line: while IFS= read -r line; do echo "$line" (cd "$line"; git status) done < repo.list > status.txt See also Understanding IFS and Understanding "IFS= read -r line" and the linked questions for ...


4

set -x DIR=/path/to/file/location TMPDIR=$(mktemp -d) rm -f -- "$DIR/combined.csv" for file in "$DIR"/doc?.csv do doc=${file##*/} #------------ doc processing temp_doc="$TMPDIR/$doc" your_code "$file" > "$temp_doc" #------------- pair doc processing pair="$DIR/pair_$doc" temp_pair="$...


4

With a combination of libarchive's bsdtar and GNU tar, you can list the contents of those nested archives without having to extract them on disk: for f in *.zip; do bsdtar -cf - --include='*.zip' "@$f" | tar -xf - --to-command='bsdtar tvf -' done GNU tar can pipe members of archives to commands upon extraction with --to-command but only supports ...


3

There are 3 questions. As comments have said, inside [[ extglob is enabled by default. You don't have an environment variable BASHOPTS. You can see this by running export | grep BASHOPTS and not seeing anything. As you quote "If this variable is in the environment when bash starts up..." you need to run export BASHOPTS in your interactive shell. ...


2

If GNU Parallel is installed: extract_list() { mkdir "$1" cd "$1" unzip ../"$1".zip parallel unzip -l ::: *.zip cd .. rm -rf "$1" } export -f extract_list parallel extract_list {.} ::: *.zip


2

You can't do it without actually unzipping the top files in a sub-folder. Something like this: set -e for f in *.zip do n=`basename -- "${f}" .zip` mkdir -- "${n}" cd -- "${n}" unzip ../"${f}" for p in *.zip do unzip -l -- "${p}" done cd .. rm -rf -- "${n}" done You should ...


2

Take the following line as an example : 00000010 72 0a 65 63 68 6f c2 a0 2d 65 c2 a0 22 23 23 23 |r.echo..-e.."###| What are these characters -- ^ ^ ^ ^ a0 is a space 20 with the high bit set ?? C2 is 42 with the high bit set ? Get rid of that weird stuff. Use vi Update 1: to create a new file Select (use the mouse) and then copy using ...


2

Take a look at the jq command it is a command line json parser. You can pull any field you would like. https://www.systutorials.com/docs/linux/man/1-jq/ For example this will return the java_version number. cat variable.json | jq .java_version If you prefer using core commands so you don't have to install anything you can use this command. cat input | grep ...


2

User accounts are typically defined by their presence in two files, and a home directory devoted to the account. You might also have created a group with this strange character in it. The two files are /etc/passwd and /etc/shadow and the directory is typically under /home/. Groups are defined in /etc/group. Warning: the following edits important system files ...


2

i googled a bit and found this find mydir -name .git -type d You could do something like this, maybe: find . -name '.git' -type d -print -execdir git status \; That would look for directories called .git, then for each, print the path to it, and go to the containing directory and run git status there. (find -exec would run the command in the original ...


1

Your issue is a simple typo as explained by Stephen already. The task of running git status in each directory given by the line in a file could be done using xargs as well: xargs -I {} git -C {} status <repo.list >status.txt This calls git -C {} status for each line in the file repo.list. The {} will be replaced by the line read from the file, and ...


1

I think this is a possibility, it doesn't compare dates, it takes advantage of the abbreviated name of the month and the number of the day and the year: $ sed -n '/Mar *[3-9].*2021\|Mar *[1-3][0-9].*2021$/p' foo.foo zpzetta/sys/win2012@zfs-auto-snap_hourly-2021-03-03-0017 Wed Mar 3 0:17 2021 zpzetta/sys/win2012@zfs-auto-snap_hourly-2021-03-03-0117 Wed ...


1

You could create a short bash script to do this but I think what your looking for is shell aliases you can add aliases to your bashrc or separate alias file. See example below. alias name=‘command —argument —argument —argument’ Now every time you run name it will run the full command. Remember aliases will not work from within shell scripts unless it is ...


1

This should do it. for file in /home/path/*.tmp ; do cat $file | awk '{print$1,"_",$3$4$5}' | sed 's/ //g' ; done


1

cat data | awk '{print $1"_"$3$4$5}' This will output what your looking for hope it helps any questions feel free to ask. Or you can do this way. awk '{print $1"_"$3$4$5}' data.dat for file in /path/to/file/holly*.dat; do awk '{print $1"_"$3$4$5}' $file; done


1

You could also do it with a simple bash script #!/bin/bash sites=("UK#13" "US-VA#2" "US-CA#1" "US-CA#2" "US-NJ#9") while true; do for site in ${sites[@]}; do echo "Connecting to $site" sleep 1 done done Change sleep 1 to sleep 3600 and add in your protonvpn command rather than the ...


1

Simple switch script and a config file run in cron or systemd-timer should suffice. #!/usr/bin/env bash set -euo pipefail SWITCHFILE='/tmp/switch' switch_to="$(head -1 $SWITCHFILE)" sed -i '1d' "$SWITCHFILE" echo "$switch_to" >> "$SWITCHFILE" protonvpn c "$switch_to" config file: UK#13 US-VA#2 US-CA#...


1

Assuming Samples.txt contains Sample_1 till 3 one per lne , we can setup an xargs command to call mv tree -F < Samples.txt \ xargs -I {} -t mv -t Analysis/{}/ \ Raw_WGS/{}_R1.fastq.gz \ Raw_WGS/{}_R2.fastq.gz ; tree -F Results: Before move... . ├── Analysis/ │   ├── Sample_1/ │   ├── Sample_2/ │   ├── Sample_3/ │   ├── Sample_4/ │   └── ...


1

If I understand you correctly, you don't need a file with the names, since they are already in the file names. Try this: for i in *_R{1,2}.fastq.gz; do # use `cp` to be sure it works cp "$i" /path/toAnalisys/"${i%_*}" done


1

DISCLAIMER: This is by no means the best way to do this or by any measure the best approach but it show how to think about these types of problems if your just doing a one off run something like this is fine but should never be used by someone other then the person writing the scripts ie. DO NOT put on a computer others use. The basis principal is think ...


1

A very simple proof of concept would this meet your needs. #!/bin/bash initial_state=$(ls -1 | wc -l) sleep 1 current_state=$(ls -1 | wc -l) rate=$(echo $initial_state - $current_state | bc) eta=$(echo $current_state / $rate | bc) echo "Current file count: $current_state rate = $rate /s" echo "Aprox. time to completion: $eta" This will ...


1

[This is essentially jimmij's comment, turned into an answer.] You can use { } to override the normal operator precedence, without creating a subshell like ( ) would. So use: condition-command && condition-command && { background-job & } And similarly for the sleep/echo example: sleep 2 && { echo foo & }; sleep 1; echo bar; ...


Only top voted, non community-wiki answers of a minimum length are eligible