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
2answers
14 views

Looping over files with specific matching numbers

I'm using a Bash script, and I have two input numbers. For simplicity, let's say the first variable is called Start and the second variable is Stop, and each can be a number between 1000 and 2000. I ...
10
votes
5answers
775 views

Echo with obfuscation

I need to print some variables to the screen but I need to preferebly obfuscate the first few characters and I was wondering if there was an echo command in bash that can obfuscate the first ...
0
votes
0answers
25 views

Resource Request! Clear and simple explanation of the syntax and situational use of special characters for Bash scripting [on hold]

When using Bash and the common tools grep, tee, sed, awk and the other common Bash-scripting utilities, I find myself getting confused on the use of special characters such as / \ ' " : ; $ and the ...
2
votes
1answer
27 views

Can I rearrange the directories in `dirs` in the order of their most recent visits?

What is the order for the pathnames of the directories stored in the stack shown by dirs -l? Are they ordered by their last pushd commands? Is it possible to order them so that they are ordered by ...
0
votes
1answer
26 views

remotely executing a command using ssh

Here I'm trying to remotely execute a command on multiple devices using ssh using while loop in bash however I'm getting output for the first IP in source file but not for others. cat HPE_FRAMES_IP ...
6
votes
1answer
271 views

Bash: Why does this Brace Expression work this way?

this is a bash 4 specific question. I am somewhat familiar with the bash Brace Expressions and I have read the manual but I do not understand how it actually works. I guess it has to do with the ...
0
votes
1answer
27 views

Bash script fails where command line works

I wrote a basic bash function to test for the occurence of a string search argument in another string. Running it from the command line gives expected results. Running the same from a shell script ...
0
votes
2answers
33 views

new line not append instead append on the end of the line

we gave the following config file ( config.txt ) more config.txt export var1=345476746 but when I am appending new parameter as echo "export var2=5645" >> config.txt we get more config.txt ...
0
votes
2answers
36 views

Get return code of first piped command using eval?

I wish to execute different commands and check the return code afterwards before moving to the next steps in the script. At the same time I also wish to log the output of the executed commands to a ...
0
votes
1answer
67 views

difference between echo ($x) and a=“($x)”; echo $a

When I execute the following in terminal: x=1 a=($x) echo $a #output: 1 echo ($x) #output: -bash: syntax error near unexpected token `$x' Why are above outputs different? Also why are the ...
0
votes
3answers
58 views

FOR loop: pass 2 variables from a file simultaniously

I am writing shell script, to extract 2 variables from a file, and have used below FOR loop. for i j in `cat list` do echo title echo total "$i" "," "$...
3
votes
2answers
232 views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
1
vote
1answer
27 views

bash + write standard output and error to both logs

in my bash script I use the following approach in order to write every thing from standard output and standard error to log.txt export LOG=/tmp/installation/log.txt exec > $LOG 2>&1 so ...
1
vote
1answer
32 views

bash to create sub directories in folder from specific file extension

In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extentions. The .bam file are trimmed and the result is the folder name that is saved in $RDIR ...
-2
votes
0answers
23 views

How to find Elapsed Time or Duration of long running bash jobs [duplicate]

I am trying to capture the elapsed time for long running jobs in Linux. So, I tried to create a small shell to assign variables and create logs Here is my code ### Code Starts Here ### read -p "...
0
votes
4answers
45 views

Bash: while loop over numbered variables

My environment can have a flexible number of variables defined with the following format: Var1Value=A Var2Value=B Var3Value=C I now would like to iterate over the variables as long as they exists. ...
2
votes
1answer
34 views

How to make alias interpretive?

I have a list of servers I often connect to, named like server001, server002... server999. I don't want to store 1000 alias hardcoded with these server names. I also don't want to write a function and ...
0
votes
2answers
35 views

bash remove members Slack from channels using xargs and sleep?

I'd like to be able to remove a batch of people from a "private" Slack channel. Use case: whoops, I just added 137 people to the wrong channel! The Slack Member ID list is obtained from an Airtable ...
0
votes
1answer
26 views

Specific fields from macOS Command “diskutil apfs list”

would appreciate inputs on the subject. I have the output from the macOS (High Sierra;FileSystem :APFS) command - diskutil apfs list. Sample output is given below: +-- Container disk5 1B5FE22B-6F4F-...
3
votes
1answer
342 views

What are these three extra chars and why do they cause such a strange error? [duplicate]

Look at these two files: File 1 File 2 They look to me entirely identical, but File 1 has 41 bytes and File 2 has 44 bytes. Now, I would not care about 3 extra chars, however, I think these chars ...
0
votes
2answers
36 views

Format the output of commands

I am currently trying to use Plink to run a few commands on a linux server to monitor a couple of things on it such as the disk space, memory, cpu usage. I have the commands that I want to use but I ...
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
50 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
64 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
223 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-...
11
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 ...
6
votes
2answers
72 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
202 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
57 views

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

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
25 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
57 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
47 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
27 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
79 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
72 views

Error Shell Programming in Linux [on hold]

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
51 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
44 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
572 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
29 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
25 views

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

EDIT: 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 this ...
8
votes
1answer
189 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
26 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
198 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
59 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 ...