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
1 vote
1 answer
11 views

Execute the output of sed as a bash script that takes inputs

sed 's/docker/sudo docker/g' ./generate.sh | xargs bash I want to run generate.sh with all docker calls replaced with sudo docker just like how it would have been ran if I called bash generate.sh. It ...
-1 votes
0 answers
9 views

being dropped into an energency shell

Starting systemd-udevd version 252.3-1-arch ERROR: device 'WID-94a4b431-cc28-4f3b-a8ec-5cf688f9eb4e' not found. Skipping fsck. mount: new root: can't find UUID=94a4b431-cc28-4f3b-aßec-5cf688f9eb4e. ...
  • 1
0 votes
1 answer
23 views

How to pass shell parameters when running a docker image?

I've implemented a bash script which accepts the following parameters SYNOPSIS run.sh: run.sh [-H|-L|-P profile -D device [-R runtime]] list the fio profiles natively supported by the docker ...
0 votes
1 answer
16 views

how to multiply columns of one file by the number in same row of another file?

I have two files both with same number of rows. File1 has 16 columns and file2 has 2 column file1 1 2 3 4... 2 3 4 5... 3 4 5 6... file2 text 10 text 11 text 12 Now I want another file with ...
  • 3
-1 votes
0 answers
17 views

How to parse complex json output with jquery

I have some JSON output that looks like this: { "result": [ { "target": "1.2.3.4", "colos": [ { "Err": ...
0 votes
1 answer
24 views

How can I set a font in a bash --x11 script?

#!/bin/bash module load rstudio srun -p interactive -N 1 --cpus-per-task=8 --time=4:00:00 --mem=80gb --job-name="RS_job" --x11 rstudio A simple bash to bring up an interactive node but ...
  • 101
0 votes
0 answers
47 views

Conditionals in awk

I am using the following bash script. Why do I get awk: cmd. line:18: match=0; awk: cmd. line:18: ^ syntax error awk: cmd. line:21: if (uaggr[i] == kaggr[j])...
  • 9
0 votes
0 answers
47 views

While loop in root shell

I want to get data from a file which can be read by root only and do some operations on the data. the code is su -c "grep $variable $file | while read -r line; do echo $line | xargs -r umount -l; ...
1 vote
1 answer
39 views

use aliases in bash script

I use aliases in my code, it works the first time and shows the current time, but the second time, when I call it shows past time(time showed before instead of current time) GNU nano 6.2 ...
1 vote
4 answers
64 views

Testing if string values match array elements

I am using a bash script and have a string of comma separated values string="string1,string2,string". There would not be any embedded commas in each string, or spaces. Want to test whether ...
  • 9
0 votes
1 answer
41 views

How to return from bash functions the right way?

This script, which i source in my terminal, offers the function _cphetzner, that is used to create a git repository. This function uses another function _feed_variable that prompts user for missing ...
  • 1
0 votes
3 answers
73 views

why doesn't A=\"\" grep $A behave like grep ""?

I am on Linux, using bash. $ A=\"\" $ grep $A nomatch "" "" <- (returned by grep) $ grep "" imatcheverything imatcheverything ...
0 votes
2 answers
54 views

How to go one path backward and store the path in variable

Suppose I am already storing a path in a variable as: tmp=/home/abc/xyz So what I want now is to go one way backward and store it in a variable as tmp2=/home/abc Please let me know how to achieve ...
2 votes
1 answer
40 views

sed with while read misses line

Can someone please explain this? I have a file: cat listi.txt sdfasdfsf123sadfasdf123 jlkjh2345ljkh245lkh4325 57hghf456ghf457gf467 Here sed misses the first line: while read line ; do sed 's/[^0-9]//...
  • 570
0 votes
0 answers
22 views

How to run ssh commands on a host after mounting via sshfs and avoid 2FA?

I have the following situation. I am able to ssh into a server but it requires 2FA each time I ssh into the server. Let's say that I do not have control over the server's configuration to disable/...
  • 101
1 vote
1 answer
41 views

Completed stumped by trying to use a decimal value in an array for Bash

Here is some simple test code. #!bin/bash cpm=(0 1 0.094) lv=1 attack=5 defense=9 stamina=16 echo $((cpm[lv])) mycpm=$((cpm[lv])) #mycpm=`echo "0.094" | bc -l` cq=`echo "$attack*$...
-2 votes
0 answers
49 views

I am new to linux and when I cd/etc/ssh it says no such file or directory

It is kali linux terminal. just installed and started to learn made my own user name and passwd and gave it privileges using sudo command now I am directed to change ssh but can't apparently.
  • 1
0 votes
0 answers
52 views

Ensuring begin and end sections

I have files with sections defined by the starting section composed oy TITLE, SUBTITLE, followed by comma separated KEYWORD. ## TITLE [SUBTITLE] KEYWORD,KEYWORD The ending is done using ## END OF ...
  • 9
0 votes
1 answer
25 views

Unable to capture exit code of a script ran inside of a heredoc

I was playing around and got stuck while trying to capture the exit code of a script I'm running within a heredoc in a Docker container. Say I want to run this command to start a Docker container ...
0 votes
0 answers
10 views

How do I make zsh treat a variable with spaces as multiple arguments to a command? [duplicate]

In bash, one variable can act as multiple arguments: bash-3.2$ debug() { > echo num args: $# > } bash-3.2$ args="1 2 3" bash-3.2$ debug $args num args: 3 bash-3.2$ exit In zsh, this ...
0 votes
1 answer
24 views

Zip files contained in a file over a loop

I have a file with X paths to files I want to zip. I have this loop: while read -r path; do zip -u "$zip_file" "$path" done <"$paths_file" I have this error: zip ...
0 votes
0 answers
22 views

Machine restart resetting my bashrc to default

I added some changes to .bashrc. But whenever I restart my machine it resets the file to default and my changes are gone. What might cause this? What is the solution? My OS is debian11
0 votes
0 answers
12 views

Why does bash date not pick up the variable changes in a loop? [duplicate]

Consider the following: $ echo "${s}" 2022-11-03 $ e=$(date --date="$s + 1 day" "+%F %T"); echo "${e}" 2022-11-04 00:00:00 I'm trying to write a loop so that I ...
  • 135
0 votes
1 answer
14 views

How to capture subshell exit code when assigning subshell output to read? [duplicate]

Consider: $ read -r a <<<$(echo "foo"; exit 1) $ echo $? 0 this returns 0, when I really expect a 1. How can I extract the real exit code from the subshell?
  • 135
1 vote
1 answer
23 views

Mouse-click stopped positioning cursor in shell (readline) in XTerm after upgrade from Fedora 18 to 36

I am using the following control sequence to set up that when I click in the command line in shell (BASH) in XTerm the cursor moves to the position. At least, it used to worked that way in my ancient ...
  • 111
2 votes
0 answers
24 views

Apply control charactes to file reddirect

Tried various existing answers, but didn't find any which entirely works. This is one line example, and show how it fails, maybe some extra switch or step can solve this? This is the content of file I ...
0 votes
0 answers
20 views

Which files should I configure to STOP AUTO-CONVERTING input method(keyboard layout) whenever I open bash shell?

I am Korean. So I have two keyboard layouts, KR / EN. There is a problem. I can't input Korean on bash shell. It is fine with output. I can read KR on bash, e.g file names. Same thing happen while I ...
-2 votes
0 answers
35 views

Adding comma separated keywords

I am using the following regular expression spc='[[:space:]]*' cmt='\/\/' ebl='\[' ebr='\]' beg_ere="${pn_ere}[[:graph:]]+ ${ebl}[[:graph:]]+${ebr}${spc}$" to match lines constructed as ## ...
  • 139
0 votes
2 answers
54 views

Find folders who have at least two files over 100 MB?

How can I only list folders who have at least two files over 100 MB in them?
0 votes
2 answers
40 views

How to pass commands around?

I have this simple script, which does nothing more than: check if an email matches a specific pattern in that case, add a tag to a taglist before quitting, print that taglist set -e lista_tag=() ...
0 votes
0 answers
23 views

Extract the second word of the files that start with the letter a in the current directory [duplicate]

Extract the third word of the files that start with the letter 'a' in the current directory. Script in linux.
0 votes
0 answers
25 views

How could we execute a program with "dynamic arguments" (loop) ? DYNAMIC ARG CONSTRUCTOR IN SHELL [duplicate]

How could we execute a program with "dynamic arguments" (loop) ? I would like to add an argument as per user interest/input. I can do it by several if conditions, But it is not practical. ...
  • 1
0 votes
1 answer
43 views

when to use test expression with if statement?

For bash scripting, I am confused about when to use the test expression with if statements. For instance, the following works. if finger | grep -q alex But the following does not. if [ finger | grep -...
  • 113
-2 votes
0 answers
54 views

Using character classes

I am getting some confusion in using the [:graph:] class. I will be using it for a pattern of non-space characters surrounded by a space. Would one use ' [[:graph:]]+ ' ? How about ' [:graph:]+ ' ? ...
  • 139
0 votes
0 answers
23 views

Sourcing variables from a script file without executing code from that file [duplicate]

There are cases where a (Bash) script will need to import shell variables from another (untrusted?) script file. For example: #!/usr/bin/env bash . /etc/lsb-release # #... make use of the contents of ...
  • 478
0 votes
0 answers
33 views

why is the command under ` (backticks) not executed? [duplicate]

I have following bash command: INPUT: $ find . -name '*.mp4' -exec echo "ln -s {} ../dummy/`basename {}` " \; OUTPUT: ln -s ./181846/181846.mp4 ../dummy/./181846/181846.mp4 ln -s ./181849/...
0 votes
0 answers
23 views

Any variable assignment would be empty inside docker

I have a long script that would be copied inside the docker image in Dockerfile and would be executed there. I'm using bash. Both in my local machine, and inside my docker. I run this code to ensure ...
0 votes
0 answers
51 views

Printing sectioned parts in terminal

I have some files that have the following construct in them. I want to print the whole sections present. The input would be other a title or keywords. ## DN [TITLE] KEYWORD,KEYWORD ## text line ## ...
  • 139
-1 votes
2 answers
47 views

rsync does not create destination folder as I want

I have the following text file ... /a/b/c/f1 /a/b/c/f2 ... /a/b/c/d1 ... where f1 and f2 are files, while d1 is a directory. I would like to copy the exact hiearchy in my destination folder (/z). ...
-1 votes
0 answers
40 views

Repeat test condition for multiple values

I have the following condition, which I want to repeat for three different values for lab. What can I do? kpn='[^,]+(,[^,]+)*' lab="keyword" lab="keyword,keyword" if [[ &...
  • 139
0 votes
1 answer
23 views

Replace backslash path for forward slash path with sed in loop

I want to replace windows server paths (\\100.100.0.0\aaa\bbb\ccc\) with linux paths /foo/bar/ on all occurrences inside all .txt files in a folder (/xxx/yyy/zzz/). For that I made a loop that does ...
0 votes
1 answer
22 views

Grep for a string on remote server returns no results

#!/bin/bash params=$(cat /var/tmp/patterns.txt) remoteLog="/home/remotefile.txt" nodes=("192.168.1.2" "192.168.1.3") for node in "${nodes[@]}";do ...
  • 11
0 votes
1 answer
23 views

Back to root_menu in script doesn't respond like it should

Menu and its submenus in single file bash script with a back to root menu for each. My issue is that the show_root_menu call sometimes just jump to the upper menu instead of the root. Bash-installer-...
user avatar
-4 votes
0 answers
45 views

Composing a regex pattern from two short ones

I have a very long regex pattern that I want to split up into two parts. Would the following construct be the correct way to do this? I want to match "## DN [TITLE]" followed by an number ...
  • 139
0 votes
0 answers
15 views

bash: adding/removing duplicate programs executes the wrong ones [duplicate]

i'm currently testing the install target (which installs into /usr/local/bin) of some software (that is also installed via my package manager into /usr/bin), and noticed that bash doesn't find the ...
  • 6,111
-1 votes
3 answers
71 views

Matching zero or more keywords separated by commas

I want to match the possibility of zero or more keywords separated by commas. Am using the following regex if [[ "$var" =~ ^([^,]+(,[^,]+)*)*$ ]]; then echo "KY MATCH" fi I want ...
  • 139
0 votes
2 answers
63 views

Get json value using regex in linux bash

I have a json file file.json like this: { "abc": "123", "def": 456, "ghi": 789 } I am trying to get value of all the keys using regex in bash terminal. ...
  • 111
0 votes
1 answer
14 views

Neovim open file with search pattern not escaped?

I'm trying to run the command: nvim "./some-file" '+/Text (with/slash)' But I get the following error: Error detected while processing command line: E486: Pattern not found: Text (with And ...
-1 votes
1 answer
38 views

Matching sections of text

I want to do pattern matching to display section of texts within a file matching the following structure. ## DN [Pattern-Matching] glob,regex ## Some text ## More text ## DN [Pattern-Matching] ends ...
  • 139
0 votes
0 answers
35 views

Pattern matching using @(pattern) [duplicate]

I would like to study some examples of pattern matching using @(pattern). Have not found actual examples after doing a search.
  • 139

1
2 3 4 5
496