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.

Filter by
Sorted by
Tagged with
0
votes
0answers
15 views

Why is my systemd startup script not running properly? (ubuntu 20.04)

I have created two systemd startup scripts as per https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/, containing the following: #1 #!/bin/bash synclient ...
2
votes
0answers
30 views

Variations in variable expansion in bash between CentOS versions

I have been writing an internal installer script and came across a behavior I don;t know how to explain. Cent6 $ _sudoers_search_string="someuser ALL=" $ _sudoers_entry="someuser ALL= ...
1
vote
1answer
25 views

How to get only memory peak usage with /usr/bin/time?

I am building a script with usr/bin/time program to monitor the RAM usage of a script and storing it in a variable so i can check if it is higher than a specified limit $mlimit, like this example ...
0
votes
0answers
20 views

bash: \"alias: command not found every time I open Terminal [closed]

so I'm not sure what happened but every time I open the terminal I get that error. bash: \"alias: command not found I've tried to open sudo nano /etc/.bashrc but the file is empty. Any way of ...
1
vote
2answers
26 views

Fixing PATH on BASH / WINDOWS

I'm running Windows 10, and have BASH terminal in VisualStudioCode. My problem is that commands such as LS do not work. After some googling, i found that using this command fixes it: export PATH=/usr/...
0
votes
1answer
22 views

How to move old logs - mysql logs

I need to move old binlogs to a directory and aso compress it before moving it to a new folder. I have a space crunch because of which we am facing issues. below commadn is not working. ls -t binlog* |...
0
votes
1answer
38 views

Iterate over files with increasing but non-contiguous number range in the name

The filename contains a pattern of the form 00035023030 which only changes from ...30 to ...35 in the last two digits. But if one number is missed form 30 to 35 like say 31, it throws the error. How ...
0
votes
0answers
12 views

Read command skip subsequent instructions in HEREDOC - Bash + Docker

I'm having trouble with a case that I see as a bug in how the shell or bash works, in which running a non interactive command supplied from a heredoc (maybe from a file too, I haven't tested) and a ...
1
vote
1answer
48 views

Using variables and for loop with array in Bash

I have declared an array called arrUsers in my shell script. I am trying to get all the users who have logged onto a linux server using the last command. I want to do something like this: declare -a ...
0
votes
1answer
31 views

Launch tmux with a command in the background without stopping said command when tmux stop running

So, I want to launch a shell command through tmux, but in the background and detaching from said tmux session...so I do it like so: tmux new-session -A -s myprogramsession \; send -t myprogramsession &...
1
vote
1answer
23 views

Command history for multiple users from sudo/wheel group

I working in an environment with multiple users who can invoke sudo with their own passwords. Most users login via ssh, call sudo -i and do "work". The problem is when it comes to identify ...
1
vote
0answers
46 views

Perl replacement with strings contain wildcard causes wrong output

I am trying to perform this regex with perl info=$(echo $info | perl -p -e 's/(?:\d[\s-.]*){12,19}/**********/g') Trying to match any digits range with 12 to 19 regardless of whitespaces,-, or . ...
0
votes
1answer
31 views

In a bash/zsh function how do I do something, then depending on the output, do A or B?

This function looks through each local git repository in folder ~/src, and does git pull on it. More and more I keep getting an error Please commit your changes or stash them before you merge. ...
0
votes
0answers
22 views

Bash script returning wrong output for file size [duplicate]

I have this simple script: #!/usr/bin/bash flimit=157286400 #150MB limit size fsize=$(stat -c%s $0) if [ "$fsize" -gt "$flimit" ]; then echo "File size is greater than ...
2
votes
0answers
28 views

Can non-expanded commands be retrieved?

I can fetch earlier commands in the bash history and alter to re-use. E.g. !-5:s/uc1/uc2/, which takes the command 5 lines back and performs the substitution. However, I want to do this five times in ...
0
votes
0answers
22 views

unable to switch user

I ran su max on a Linux machine, where max is the username. However, instead of asking for the password of max, the command line just showed $. I used bash and it let me in, but I want to know what is ...
1
vote
1answer
45 views

How to substitute value of var with sed

I have a mapping of vars and I need to substitute the value of a specific vars dynamically in a bash script. My vars are like this: array = { node1 = [ { "apacheversion&...
0
votes
1answer
34 views

How do I find duplicate lines in multiple files within folders

when i want to find duplicate lines between two files i use this command comm -12 <(sort file1.txt) <(sort file2.txt) or sort file1.txt file2.txt | awk 'dup[$0]++ == 1' But, how do I find ...
1
vote
0answers
16 views

How can I configure tmux to make only the first window of each session load a login shell (& all other subsequent panes/windows as non-login shells)?

Hopefully the title of this post is descriptive enough. As well-documented in the tmux manuals, tmux launches a login shell every time a new tmux window or pane (split) is launched. Instead, how can I ...
5
votes
2answers
2k views

Why does the bash shebang work, but the sh shebang doesn't, for a string substitution

I've been tracking down an issue I've been facing in a buildkite script, and here's what I've got: Firstly, I enter the shell of a docker image: docker run --rm -it --entrypoint bash node:12.21.0 ...
2
votes
1answer
24 views

How to make multiple parallel calls to function which makes post request in unix?

I am having a function A, which takes an argument fileName and then makes a curl post call with that file to employment Server.The function pseudocode will look as : function A(filename) { // read ...
2
votes
1answer
134 views

Script function call: function vs $(function)

Taking how reference the following code for simplicity #!/bin/bash number=7 function doSomething() { number=8 } doSomething echo "$number" It prints 8. But with: #!/bin/bash number=7 ...
2
votes
3answers
68 views

A universal `while read something` to `parallel` conversion/replacement

I have a ton of scripts which do this: command | while read something; do a long list of commands done Has anyone ever thought of how to run all the commands fed through the pipe ...
0
votes
1answer
39 views

Centos 8.4 what is POSIXLY_CORRECT and what makes it change?

I am testing using this script from github: https://github.com/rocky-linux/rocky-tools/blob/main/migrate2rocky/migrate2rocky.sh I tested this yesterday and it worked fine. Today I reverted to a ...
0
votes
1answer
58 views

Convert this regex to be friendly within sed

I am trying to perform this regex with sed, but seems like sed does not support? It says invalid character range echo "$info" | sed -e 's/(?:\d[\s-.]*){12,19}/*/g' Trying to match any ...
2
votes
3answers
76 views

Regex match shell variable as a pattern (case insensitively)

A snippet of a typical tsv file I have used 10 Interstellar Main Theme Extended UDVtMYqUAyw 11 Journey XvG78AmBLc4 12 Jurassic Park Music & Ambience Amazing Soundscapes and Music ...
1
vote
0answers
31 views

automatically reset sshfs when it locks up, remount fails unless done manually

i have 2 local dirs on my server mounted on a remote server. Local maintains connections with autossh -M 23 -R 24:localhost:22 user@server While remote mounts with dirs-sshfs.sh sshfs -o reconnect,...
0
votes
1answer
45 views

Run a Bash Script from Python and import the exported environment variables into Python

I have the following Bash script called Test_Vars.sh #!/bin/bash #----------------------------------------------------# # Environment Variables being used in the process # #------------------------...
1
vote
1answer
33 views

bash I/O redirection - how to append to stderr

I have a script that loops over some big collection of data and performs some lenghty operations. Then i need to sort | uniq -c its output. So to let it know that its alive, I print a dot every N ...
2
votes
2answers
145 views

What does `ln /path/to/file -i` do in a setuid'ed script?

I was making a Bash script with the setuid permission on, but it didn't work. So I found my solution here: Why does setuid not work? and Allow setuid on shell scripts Now my script works fine and ...
0
votes
0answers
29 views

bash script for for multiple commands run in one file [closed]

I have large data and I want to calculate daymean, daymax, daymin and other variables of each file. I want to make a script. I try this type of script: cdo daymean tasmax_day_ACCESS-ESM1-...
11
votes
2answers
804 views

Command 'time' works on its own but not in a pipeline

Consider the following: # time sleep 1 real 0m1.001s user 0m0.001s sys 0m0.000s # echo foo | time sleep 1 bash: time: command not found Um... wut? OK, so clearly Bash is searching for ...
-4
votes
1answer
42 views

Use exit, but do not close terminal, in bash script

I have created a shell function to comfortably use desktop search tool baloosearch. I created it as a function for a reason. Now, in this functions I need to use exit command to quit loops, ifs or ...
4
votes
4answers
343 views

Read file and store as array without skipping empty strings

File.tsv is a tab delimited file with 7 columns: cat File.tsv 1 A J 1 2 B K N 1 3 C L O P Q 1 The following reads File.tsv which is tab delimited file ...
2
votes
2answers
88 views

bash multiline string variable assignment failing

in bash why does this work fine: $ cat test1.sh #!/bin/bash echo "some text" \ "some more text" $ ./test1.sh some text some more text but this fails $ cat test2.sh #!/bin/bash ...
6
votes
2answers
744 views

What is more efficient or recommended for reading output of a command into variables in Bash?

If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the examples below: IFS=: read user x1 uid gid x2 home shell <<<...
1
vote
0answers
25 views

The weird order when concating variables and string with '_' [duplicate]

I want to concatenate a variable and a string. while read subject; do pathproc=/projects/guo_lab/cbis/users/yang/DICA_result echo ${pathproc}/${subject}"_"weight done < /projects/...
0
votes
0answers
22 views

Will this auto-respawn bash script work?

I've been having issues with my eth miner, nsfminer, crashing on me when I leave it on at night. Sometimes this occurs after 2-8 hours of mining, while sometimes it doesn't occur at all. It usually ...
1
vote
1answer
32 views

protection for duplicate sed replacements

This is more of a architectural question: I have a script that does some in file sed replacements/additions like: sed -i 's/MY_VAR = 1000/MY_VAR = 1000\nMY_VAR2 = 500/' file.txt which works fine but ...
1
vote
2answers
53 views

Can't delete multiple files with spaces on name with rm

I'm working on a deploy script for my dotfiles, they are stored on a Git bare repository, from which i git checkout it's files into my home directory, in order to seamlessy do it without thousands of ...
0
votes
0answers
52 views

sed: unterminated `s' command [duplicate]

The following sed command gives a sed unterminated `s' command. It has to do with the variable that I put in ($header): sed -i "1s~^~$header~" $1"/main.cpp" The following is the ...
2
votes
3answers
134 views

How do I split a string by a delimiter resulting in an unknown number of parts and how can I collect the results in an array?

I need to process some strings containing paths. How do I split such a string by / as delimiter resulting in an unknown number of path-parts and how do I, in the end, extract the resulting path-parts? ...
0
votes
1answer
25 views

How to continue script commands, functions & variables after chroot?

I have written a BASH script that would prepare and install everything during ArchLinux initial installation. The script would work fine and execute everything successfully until it reaches the arch-...
1
vote
0answers
16 views

How to extract multiple occurences of one capturing-group from a regex-match?

I have a string of following format to be matched ./foo/baz/bar/filename.c My regex looks like this regex=$'^(\./)?([a-zA-Z0-9_-]+/)+([a-zA-Z0-9_-]+\.[a-z]+)$' The test looks like this [[ $search =...
5
votes
1answer
316 views

Why does adding a . in %s prevent the number from getting printed?

I am trying to learn commands in Bash and came across these examples. Why does adding a '.' prevent the sequence number from getting printed? This is the behaviour I want, but I couldn't find anything ...
0
votes
1answer
23 views

Why Bash doesn’t pass the errexit option to command substitutions?

Shell options set by set builtin are inherited in sub-shells (at least the errexit). This can be proved by: set -o errexit function foo() { echo "foo:$BASHPID" false echo 'after'...
1
vote
0answers
46 views

Bash file descriptor redirection mystery [duplicate]

This is a mystery encountered at work today. Note that this behavior seems to be specific to a binary that I do not know the contents of, but any ideas as to how this phenomenon could occur would be ...
0
votes
0answers
16 views

Batch file conversion for VLC - Bash not working - transcoded: No such file or directory

I want to process a bunch of WAV audio files to a certain format. VLC offer Unix/Linux instructions here on how to batch process files. Here is the script, when I run I iterate through the files, an ...
1
vote
0answers
25 views

Unexpected behavior when querying the PID of bash or zsh when using the --command/-c flag

I am observing odd behavior when examining the PID of certain shells when executed in a non-interpreted context. In the below examples, I see that the PID is pointing to the shell, as expected. sh-4.3$...
1
vote
0answers
20 views

Getting different PIDs from unshare

Here's some of the basic code inside a script called test.sh. bash -c "sleep 10; echo \$(pidof unshare)" & sudo unshare --mount --uts --ipc --net --pid --fork /bin/sh -c " ... do ...

1
2 3 4 5
444