Stack Exchange Network

Stack Exchange network consists of 174 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.

-1
votes
0answers
42 views

bash shell script for following situation?

I would like to use a bash script for some .raw image merging. I have 4 .raw images in directory /home/output and the file names are 1.raw, 2.raw, 3.raw, and 4.raw. All the files (.raw) have the same ...
1
vote
4answers
52 views

Find file , create subdirectory and move

I have the follow Direcory tree. Comb | |--- 1.json2 |--- 1.cc.json2.ml |--- 102.cc.json2.pre2.ml |--- 1.json2.pre1 |--- 102.json2.pre1 I need create and bash to make this result. Comb |--| |...
-1
votes
0answers
61 views

bash: find exec in a subshell with multiple commands

I am using find and then executing a set of commands in a subshell as follows: find ${CWD} -name "Sourced.sh" -exec bash -c '\ i="$1"; echo ${i}; \ cat ${i} > ${i}.temp; \ "${dScriptP}"/Substitute....
1
vote
1answer
47 views

Multiple commands inside a docker container bash script

I want to excute some commands inside a container but the second one doesn't want to be executed inside the container so grep can't find the file in home directory of my container. Does someone has ...
2
votes
2answers
94 views

Run commands in parallel, but kill both if parent is killed?

Is there any way to run two commands in parallel in Bash such that, if the shell is killed forcefully, then both of the commands are guaranteed to be also killed? A simple & won't work because if ...
5
votes
2answers
275 views

Subtract time using bash?

Is it possible to use bash to subtract variables containing 24-hour time? #!/bin/bash var1="23:30" # 11:30pm var2="20:00" # 08:00pm echo "$(expr $var1 - $var2)" Running it produces the following ...
0
votes
3answers
45 views

Bash: shell script create variables? [duplicate]

I'm trying to have a bash script create a variable and have the variable persist in the terminal until the terminal closes (not permanently). I thought export was what I needed but it didn't work. #!/...
1
vote
2answers
66 views

run a shell script which reference another script on ssh

I have two bash scripts main.sh and a util.sh, and I reference utils.sh in the main.sh by using . util.sh. Now I want to run main.sh via ssh. Obviously, this won't work: ssh user@host "bash /dev/...
1
vote
2answers
56 views

how to convert a string to a float and then use it in a conditional operation? [duplicate]

I'm trying to write my own bash script that detects if Debian's release version is less than 9.0 code: VERSION=$(cat /etc/debian_version) echo $VERSION if [ "$VERSION" -lt "9.0" ]; then echo "...
0
votes
1answer
35 views

Bash: Set variable equal to a string substitution [duplicate]

I'm trying to replace a substring in $1 with another, AND set it to a variable. (saved as testStringReplacement file) #!/bin/bash secondString="Sara" myString= "${1/Suzi/$secondString}" echo "...
5
votes
4answers
301 views

Pairwise combinations of filenames

If I have n files in a directory, for example; a b c How do I get pairwise combinations of these files (non-directional) to pass to a function? The expected output is a-b a-c b-c so that it can ...
0
votes
1answer
28 views

Set IFS for for loop within subshell

IFS='\n' for i in "$(IFS='\n' printf 'abc\nxyz\n123 456\n')"; do echo "????" echo "$i" done echo "output" echo "${args[@]}" The following outputs: ???? abc xyz 123 456 output How can I get ...
1
vote
0answers
25 views

How to keep screen running after exiting the command that runs in it?

I have the task to start a detached screen session (e.g. when the system reboots) and then to be able to connect to it and interrupt/kill the running process without the screen to terminate. ...
0
votes
1answer
64 views

How can I stop a child process of a subshell (as per SIGSTOP) before the subshell exits?

In bash, when running ( sleep 123 &), the sleep 123 process will continue running, when the subshell exits. How can I stop the sleep 123 process before its parent subshell exits? I'm trying to ...
6
votes
3answers
661 views

Does bash have a color command, as seen in MS-Windows CMD? [duplicate]

Does a command like color exist in bash? There is a command in Microsoft's cmd, called color. I know that, in bash, there are special characters that allows you, during the echos, to change the text ...
0
votes
1answer
55 views

Confused why script does not exit

I have this script verbatim: #!/usr/bin/env bash handle_json(){ while read line; do cat <<EOF {"@json-stdio":true,"value":{"mark":"$1","v":"$line"}} EOF done; } ( echo; echo; echo '...
1
vote
1answer
42 views

diff between END and EOF

Is there any difference between: cat <<END {"@json-stdio":true,"value":"$pack"} END and cat <<EOF {"@json-stdio":true,"value":"$pack"} EOF ?
0
votes
1answer
34 views

how to add part of similar string from one file to another file

I have a txt data like this (df1.txt) >tr|A0A1B1L9R9|A0A1B1L9R9_BACTU MNKQLFLASLKETQKSILSYACGAALYLWLLIWIFPSMVSAKGLNELIAAMPDSVKKIVG MESPIQNVMDFLAGEYYSLLFIIILTIFCVTVATHLIARHVDKGAMAYLLATPVSRVQIA ...
0
votes
0answers
42 views

How to archive into multiple zip a directory containing several millions sub directory?

I have large directory that contains several millions+ sub-dir, each sub-dir contain 3 or less image files. What is the most efficient way for me to zip them so I can move it to a new server? The sub-...
7
votes
5answers
470 views

Executing a bash script or a c binary on a file system with noexec option

Can anyone explain in details what is going on with the following. Let's imagine I am mounting a directory with noexec option as follows: mount -o noexec /dev/mapper/fedora-data /data So to verify ...
0
votes
3answers
50 views

AWKing an SSH command in bash script gives bad output

I am trying to pull information from a simple bash script that pulls some data from a java server. When the SSH variable is run in the script, I can't seem to run awk on it to pull out the information ...
2
votes
1answer
42 views

fswatch: update file permissions on creation

I have a directory and I want when a new file or directory is created inside to update their permissions. For now, I achieved to do it with fswatch and new file/directory creation is detected, ...
0
votes
1answer
58 views

bash and curl commands gets errors : bash: /dev/fd/63: No such file or directory and curl: (23) Failed writing body (0 != 8192)

I am trying to install Litespeed in my Debian instance under Google cloud. I try : sudo bash <( curl https://get.litespeed.sh ) my_serial_number I get : bash: /dev/fd/63: No such file or ...
0
votes
1answer
70 views

Bash output redirection to new file each time command is run

I have a Bash one-liner that redirects the output of a command to a new, fresh file each time the command is run. Logging the output of each time the command is run is important (I'm using ls here as ...
-5
votes
1answer
64 views

Does exiting a login shell necessarily log out of the OS?

Bash manual says logout [n] Exit a login shell, returning a status of n to the shell’s parent. On a virtual console of Ubuntu, I first log in, and in the login shell, run: $ pstree -paus $$...
0
votes
1answer
61 views

Bash prompt configuration

I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly. I used zsh before, and for some reasons I want to go back ...
0
votes
0answers
36 views

Send string to another process stdin [duplicate]

Example process waiting an input sent to background $ read -p "Input text and hit ENTER to exit" & I try to write to stdin (fd/0) with \n $ echo -e "ok\n" > /proc/$!/fd/0 but $ fg read -p ...
1
vote
1answer
48 views

How to detect dot (.), underscore(_) and dash(-) in regex [closed]

I need to process information dealing with IP address or folders containing information about an IP host. I need a pattern that can identify (match) IP addresses, whether an actual url, name of ...
0
votes
1answer
17 views

ANSI C quoting for tab and newline sometimes does not work

I am trying to use a newline in bash. I found that I need ANSI C quoting for that (i.e. $'\n'), but this often does not work for me. So I am wondering what I am doing wrong. # This works >> ...
2
votes
3answers
241 views

Problem with shift in bash

Tried to use a wrapper around find but hitting the following problem. I want e.g to provide a few directories as arguments but the last argument is always a number that indicates how old data should ...
1
vote
1answer
31 views

Failing on errors inside a function which is called on the left-hand-side of an && expression

I am working on a Bash script with several functions. I would like to exit the script if any commands return an nonzero exit code, unless in a context where that code is being explicitly handled (such ...
1
vote
1answer
18 views

Check if a give port is included in output, if it is run another command

I have a commandb: printf '%s' "${PORTS[0]}"; printf ',%s' "${PORTS[@]:1}" That lists ports from another command that output of commandb looks like: 2200,800,8000 These ports are stored in a file ...
0
votes
2answers
35 views

Move .txt files into subdirectories

I have multiple directories in a single directory. Astrocytes_BloodCells_GeneSet/ Astrocytes_Polydendrocytes_GeneSet/ Endothelia_Neurons_GeneSet/ Microglia.y_Neurons_GeneSet/ ...
0
votes
1answer
44 views

how to get several commands into one variable for ease of use

I am writing a script and I noticed that a certain line of code is constantly being reused. So I thought why not put it into a variable for ease of use, and when something changes, I only need to ...
1
vote
2answers
54 views

How can I get the Linux terminal to look like Windows Git Bash?

Before anyone says it, yes, I know this is a duplicate, except when I copy/paste that code into tilde slash period bash(no period)rc, the terminal hasn't changed at all. I'm running Debian on Virtual ...
10
votes
2answers
549 views

Why can I not use variables as prefix to a command to set environment variables?

Normally, it is possible to set an environment variable for a command by prefixing it like so: hello=hi bash -c 'echo $hello' I also know that we can use a variable to substitute any part of a ...
0
votes
2answers
40 views

Running multiple command against files matching a brace+glob pattern without repeating it

I would like to run a series of commands against a set of files matched by a braces-and-globs pattern, without copy-pasting the pattern all over the place. I've been trying to do this by putting the ...
1
vote
1answer
21 views

Using the output of a command to generate an ssh login

I've got a script that I like a lot which generates a two-hopper ssh + port forwarded command. ssh -N -f -o 'ControlMaster Auto' -o 'ControlPath /tmp/gimme_access' -o 'ControlPersist 1m' -L 6473:33....
0
votes
0answers
35 views

Order of scripts run before bash starts

I'm studying the scripts that run before a bash shell started by the user starts. As far as I understand, the order is: /home/username/.bashrc (modifiable by user) /etc/bashrc (modifiable by root) /...
1
vote
1answer
36 views

Hex code for '(' in bash regex

I have a strange behaviour in shell. When I try to match '_' in regex with its hex code it works, but not with '('. $ regex1=$'\x5f' $ pattern1='_' $ if [[ $pattern1 =~ $regex1 ]]; then echo yes; ...
0
votes
4answers
54 views

Calculate date/time difference form entries in two files in bash script

I have two files (STARTED and COMPLETED) that look like this: STARTED FILE: 2018-01-30 10:21:41 2018-01-17 12:22:50 2018-06-27 23:09:20 INVALID INVALID ... for 800 Rows COMPLETED FILE: 2018-01-30 ...
1
vote
1answer
103 views

How do I split a string into two strings?

I already know how to put h4 h7 h8 h9 h7 into an array with space as delimiter, but after that I am trying to separate the h from the numbers to compare the numbers to each other. How can I do split ...
1
vote
2answers
32 views

Using find, how to classify like ls -F ? (directories with a trailing slash)

I use find to get a list of files, then I grep it to do a path matching : $ find pc* | grep -i arthur pc6/arthurv/untitled-2.py pc6/arthurv/untitled-3.py pc6/arthur.py pc9/Arthur 4C pc9/Arthur 4C/...
1
vote
0answers
18 views

Renaming many files to their parent directory name [duplicate]

I want to recursively change many files named raw.tex to parent-directory-hw.tex. Is there a simple scripting solution to this problem? For example, running the script on . `-- root |-- baz |...
1
vote
2answers
42 views

menu working, but not with |bash command

below is a script that displays a menu, when I run it like ./menu.sh it works, but when I run it like this: ./menu.sh | bash I get a lot of commands not found. The reason I want to run it with | ...
2
votes
1answer
40 views

Bash string to integer comparison

Here I see the [[ allows comparison between string and integer. [usr1@host dir]$ echo $count1 [1] "0" [usr1@host dir]$ echo $count2 13188 [usr1@host dir]$ if [[ $count1 -ne $...
0
votes
0answers
27 views

Bash Parallel MySQL Dump

I have a project on AWS which will eventually have over 100 client databases each estimated in the 1~2GB size. I need to do daily backups of each database via mysqldump not the standard AWS RDS daily ...
0
votes
0answers
26 views

source bash string instead of file

I want to source a bash function from a string instead of a file at the command line, so instead of this: source file.sh I want to do something like: source `cat <<EOF some_func(){ echo ...
0
votes
2answers
36 views

how to alignment the output of the last fields

the bash script for i in $script_name do echo -en "running the script - $i\t - " exec 3>&1 4>&2 var=$( { time /tmp/scripts/$i 1>&3 2>&4; } 2>&1) # Captures ...
10
votes
4answers
628 views

How to insert newline characters every N chars into a long string [duplicate]

Using common bash tools as part of a shell script, I want to repeatedly insert a newline char ('\n') into a long string at intervals of every N chars. For example, given this string, how would I ...