Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
18 views

Get the path of sourced bash script [duplicate]

There is my simple script that I try #!/bin/bash DIR="$(cd "$(dirname $0)" && pwd)" echo $DIR When I execute it like $ ./my_script.sh, get the path correctly. But, when I source it ...
2
votes
1answer
54 views

Why am I getting “No such file or directory” when I try to execute a binary? [duplicate]

I'm trying to execute the firefox binary: root@454316a1a89a:/tmp/firefox-portable# ls -la total 220 drwxr-xr-x 4 jenkins jenkins 4096 Mar 18 21:15 . drwxrwxrwt 1 root root 4096 Mar 18 21:...
3
votes
3answers
98 views

tee into different variables

From the bash code command1 | tee >(command2) | command3 I want to capture the output of command2 in var2 and the output of command3 in var3. command1 is I/O-bound and the other commands are ...
6
votes
2answers
233 views

How to read string as hex number in bash?

I have the bash line: expr substr $SUPERBLOCK 64 8 Which is return to me string line: 00080000 I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-...
12
votes
2answers
1k views

Exit shell with shortcut (not typing exit) that closes session properly

I use a ProxyJump command for a number of ssh sessions I use daily, and also switch users a lot on these sessions and having to type exit 3 or 4 times in a row isn't too fun. I am aware of newline + ~...
0
votes
0answers
33 views

How to get PIDs connected to another PID's standard input/output/error?

After something like first_command | … | last_command & $! is set to the PID of last_command. How can I find the other PIDs in this pipeline? Especially, is there a convenient way to find the PID ...
7
votes
2answers
79 views

Inverting an associative array

Let's say I have an associative array in bash, declare -A hash hash=( ["foo"]=aa ["bar"]=bb ["baz"]=aa ["quux"]=bb ["wibble"]=cc ["wobble"]=aa ) where both keys and values ...
6
votes
1answer
207 views

Variable completely messes up echoed string

So I really have no idea how to better describe this than the title. So I discovered this website called pwnedpasswords, where you can apparently check to see if your password's sha1 hash has been ...
-5
votes
2answers
58 views

Bash - How to find the longest txt file in a folder? [closed]

I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it
0
votes
1answer
27 views

echo, pipe and command substitution

I want to substitute an echo command followed with | (pipe). For example, $(echo "echo 'hello' | cat") returns 'hello' | cat I expect this to behave like echo 'hello' | cat which returns hello ...
-2
votes
2answers
63 views

Script not correctly printing the correct elements of the array

So basically I have to write a bash script that examines some specific files from the working directory (which are named file.00.txt up to file.24.txt). The thing is, 3 of them are exatcly the same ...
0
votes
1answer
48 views

Syntax for checking if variable contains digits only in bash

I was reviewing some old scripts on my machines and I saw this if expression and I have no idea what it is doing. Can someone explain it? if ! [[ "${count// /}" =~ ^[0-9]+$ ]] then echo 1 else ...
2
votes
2answers
69 views

Killing a process and diffing its result

I've been trying to write a simple bash script, but I cannot get it to work. I want to: Start a program, feeding it input from a text file (./prog < input1.txt) Wait a short amount of time and ...
1
vote
1answer
28 views

Taking input in a script and making sure there's only one parameter

I'm currently working on an assignment where I have a script that is basically just getting to learn using grep with different regex's. I have the script written except for the first part where I am ...
1
vote
1answer
88 views

Passing arguments from one script to another

Let's say I am in a Bash script and am sourcing a file. How do I pass variables to another script after I source the file like this. sed -i 's/ = /=/' $file source $file Let's say file contains ...
-8
votes
2answers
75 views

Error Shell Programming in Linux [closed]

I need to fix my code? i=0; bil_genap=0; bil_ganjil=0; echo -n "Batas loop : "; read batas; if [ -z $batas ] | [ $batas -lt 0 ]; then echo "Ops, tidak boleh kosong atau Batas loop ...
0
votes
0answers
41 views

Escaping a string for a parameter inside a script [duplicate]

I have a shell script inside of which I call a command with several arguments. When I call the command from the terminal, the proper syntax is: command --foo='bar baz' Inside my script, I want to ...
0
votes
1answer
40 views

-bash: alias: /Users/username/.bash_profile”: not found

I'm trying to add some aliases to my bash profile, but it's not working for some reason and I get these errors when I open a new terminal or execute bash profile with . ~/.bash_profile. These are ...
2
votes
0answers
53 views

Good projects for bash and awk [closed]

I am learning bash and awk programming, and have gotten to the point where I want some interesting projects to work on to improve my programming. At the minute, the beginner stuff is getting too easy, ...
-1
votes
1answer
68 views

nohup: ignoring input and appending output to 'nohup.out'

I ran the following command nohup conda activate shuffle_pair_end_reads && python3 shuffle_pair_end_reads.py \ fastp-filtered-merged4racon/merge_R1.fq.gz \ fastp-filtered-merged4racon/...
0
votes
1answer
34 views

Preserve presence of last newline when assigning to variable [duplicate]

In bash, when an output is captured into variable using $(...), an annoying newline is appended. However, I have an output that sometimes ends in a newline, and sometimes not. I want the output to be ...
7
votes
4answers
580 views

How can I track script which gives me “command not found” right after the login?

When I login, I have these messages: -bash: $'\r' : command not found -bash: $'\r' : command not found -bash: $'\r' : command not found It is quite clear that it is caused by Windows-style line ...
0
votes
1answer
34 views

“nohup cat” — write the complete content to the log file rather to concatenate file

I used the below command nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz > fastp-filtered-merged4racon/merge_R1.fq.gz > merge_R1.out.log 2>&1 & but unfortunately, the output went ...
2
votes
1answer
29 views

Terminal runs commands on startup and I cannot find where they are coming from

I have accidentally put winehq.key into /etc/bash_completion.d/ in the process of docker-machine completion installation. I've tried to set up docker-machine auto completion and followed these ...
8
votes
1answer
199 views

Pass associative array as parameter list to script

In a script I have an associative array like: declare -A my_vars=( ["key1"]="value1" ["key2"]="value" ) Is there a single command to transform that into a parameter list in the form --key1=value1 --...
0
votes
0answers
13 views

How to update display command result in one line? [duplicate]

I want to clear and update display text in loop without new line. I try the following code: echo -ne "some text\r" But it is not really update the line but just overwrite the line without clear the ...
1
vote
1answer
27 views

understanding backslash in POSIX standard

I've seen interesting video about POSIX standard on youtube. It was part of lecture, asking if anyone knows the result of echo \\\\\\ in bash, and sh(POSIX standard?) sh-3.2$ echo \\\\\\ \\ bash$...
5
votes
1answer
203 views

Bash: What does “masking return values” mean?

shellcheck generated the following warning SC2155: Declare and assign separately to avoid masking return values For this line of code local key_value=$(echo "$current_line" | mawk '/.+=.+/ {print $...
0
votes
2answers
63 views

Echo Results of a Variable in Sed Replacement

I have a file called LoginExcInternal.txt which has data that looks like the following: Name1 OpenFin/111.111.111.111 Name2 OpenFin/111.111.111.112 Name3 Chrome/111.111.111.111 These two ...
0
votes
0answers
53 views

How do I stop my terminal from clearing the command when I hit enter

I am using mintty under Cygwin on Windows 10. I don't know why this started happening but suddenly everytime I type a command and hit enter, the command and all the scrollback text is cleared. I don'...
0
votes
4answers
69 views

How to shuffle file names randomly in a directory

Say i have a directory of filenames: file_010.ext file_011.ext ... file_99.ext What's the simplest way to take each file and randomly rename it to any other name in the directory, without there ...
-1
votes
0answers
19 views

How to convert a byte stream into a useable path

Assume one has a \n in a directory name and one cd's into that directory. How can one alter the following commands so that the final ls will always work? pwd | od -A n -t x1 --width=255 | tr -d '\n' ...
1
vote
2answers
32 views

wrong echo command

I am having a little problem with my ubuntu16.04 terminal. I wanted to have access to a data-base through the use of the : echo source /Infos/bd/config11 >> .bashrc echo source /Infos/bd/...
1
vote
1answer
45 views

Bash displaying gibberish after specific incoming request

I set up a new, basic Linux server (CentOS in this case) just for testing purposes. In there, without any firewalls and all that I'm running a Python web application. Basically I type python run.py ...
0
votes
1answer
13 views

Linux bash forking process (inotifywait)

I have a running bash script that is forking. It looks like this: #!/bin/bash /usr/bin/killall inotifywait /usr/bin/inotifywait -mrq -e CREATE --format %w%f /home/sftp/folder1/ | while IFS= read -r ...
0
votes
2answers
52 views

Add line breaks to Grep Commands

How can I add a few line breaks? I want it to show OpenFin category, have a line break, Chrome category, another line break, then memoryInfo. Here is what I have so far: cat LoginExInternal.txt | ...
0
votes
1answer
29 views

How to append line with strings at the end of variable?

We have the following line in file more file USA_FORMAT="-XX:LOP83746=5M -XX:+YU3635-2837" and we want to append the following strings (line) also at the end of USA_FORMAT variable /usr/jdk64/...
0
votes
1answer
14 views

Counting instances in a variable, then reformatting rows/columns within bash script

Please forgive any formatting errors I consider myself a complete beginner. Within a Batch submission script I have a file generated called "nodefile.123" that looks like: bear-pg0208u33b bear-...
0
votes
2answers
62 views

Bash Script Array Separated by pipe and bracket

I need to create a bash script that would transform the text file content separated by | and ] ... Text File Content for example: Col1|Col2|Col3]P1]P2]P3|D1]D2]D3|Col4| ColA|ColB|ColC]PA]PB]PC|DA]DB]...
1
vote
1answer
20 views

Unable to have a local variable with the same name as a global read-only variable

#!/bin/bash readonly x=2 function test { local x=1 echo ${x} } test echo $x The result is, readonly-local-test.sh: line 6: local: x: readonly variable 2 2 When the variable is read-only this ...
0
votes
2answers
90 views

Getting exit code from curl in bash script

I want to take the output of simple.sh, a script from the internet and check its exit code. I on OSX #!/bin/bash $(curl -s http://127.0.0.1:8000/simple.sh) if [ -z "$?" ]; then echo "Good" ...
1
vote
1answer
23 views

How do I set a bash variable that contains another variable? [duplicate]

I am trying to set the variable service to be the value of var1=first/second echo $var1 | cut -d '/' -f 1 var2=$var1 | cut -d '/' -f 1" echo $var2 The result of echo $var1 | cut -d '/' -f 1 is "...
0
votes
1answer
52 views

Passing variable to “authorization: bearer” header with Curl and Bash

I've been trying to make this work for a while now, and I just can't see why it's not working. It's just a simple script that's supposed to return either 200 (if it works) or 400 (if it doesn't). The ...
-1
votes
1answer
45 views

How to use the “for .. in” loop

#!/bin/bash if [ ! $# -eq 2 ]; then echo "You have not inputted the correct amound of arguments. usage: $0 file user Where file is the file to search and user is the user to find" fi if [ ! -e $1 ];...
1
vote
2answers
40 views

Expanding only certain variables inside a heredoc

This is an extension of the question I asked . Passing directory from command line to shell script I have a script which writes another script using a heredoc. I need to be able to write unexpanded ...
0
votes
0answers
17 views

Passing directory from command line to shell script [duplicate]

I want to pass directory as a command line argument to the shell script. #!/bin/bash sourcedir=/home/dir/data cd $sourcedir find "$PWD" -maxdepth 2 -name \*_R1*.fastq.gz > list1 fastq_list=$...
1
vote
1answer
30 views

shellcheck: “In POSIX sh, ulimit -H is not supported”

I am using shellcheck to fix warnings in a sh script. The script checks for the hard fd limit with: ulimit -H -n It sets the soft fd limit with: ulimit -n "$MAX_FD" This generates the shellcheck ...
0
votes
1answer
17 views

ffmpeg - how to split a .aac audio-file into small parts, exactly 4.00 seconds in size (so ignoring keyframes)

How can I split the audio file .aac into small parts of exactly 4.0 seconds, ie. with ignoring keyframes? The original video file was in .mp4 format. From this video file I got an .aac audio file. ...
0
votes
0answers
23 views

Line wrap broken after using PS1

The line wrap is working weirdly when I use the following PS1: export PS1="\[\033[00;32m\][\d \T] \[\033[0;31m\]\u@\H:\[\033[0;37m\]\w\[$(tput sgr0)\] \n\[\033[0m\]$ " It is line wrapping onto the ...
1
vote
1answer
36 views

Checking for invalid date in bash script

I am checking for a valid date scrpt.bash test 2019-05-03 date -d $2 2>: 1>:; c=$? If $c is 1 then the date is invalid. If I enter 2019-05-03 I will get a 0 which is correct. If i enter 2019-...