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.

Filter by
Sorted by
Tagged with
1
vote
2answers
26 views

Save output of command in array

I am executing this command ar=($( ssh -i id_rsa -T -y root@1.1.1.1 sh -c "id;whoami;ps aux")) I need to save the output of each command executed into the array and call the array, but i ...
0
votes
1answer
28 views

My confusion about the usage of double quotes in bash

Recently, I am busy coding the bash script to feed my needs. However, during the coding time, I found the usage of double quotes is contradicted with each other at some times. For example, I try to ...
-3
votes
1answer
35 views

What is this code supposed to do?

#block 1 # # if [ $# -ne 1 ]; then exit 1 fi ID=`echo $1 | awk -F / '{print $NF}'` # Set the user agent ID to use USER_AGENT="Mozilla/5.0" # Check we have the tools we need which wget ...
7
votes
2answers
188 views

How to loop through a CSV with multiple lines to grab 2 variables?

I have a CSV file that contains usernames and passwords. The file looks something like this: user1,password1 user2,password2 user3,password3 I need to loop through each line to grab the username and ...
0
votes
3answers
31 views

run another while read after first one finished

I want to run another while read with different input file + python script after first one is finished. Example code: #!/bin/bash while read -r line; do python3 script.py -d $line --output test ...
1
vote
1answer
47 views

Use find -exec in a script

I'm a long-time find and bash user, but this seems to be the first time I've tried to run a find command in a script. I'm trying to loop through all the project source files to find the first argument ...
-1
votes
0answers
31 views

array isn't printing the count it got appeneded in it

I'm declaring an array and keep adding in it and add a comma(,) next to each addition. When I count the number of appends done on that array it shows me 1 though it shows all all the values appended ...
0
votes
3answers
31 views

Ubuntu terminal not showing path

I have added one line in bashrc and after that terminal is not working as expected, no path is showing and I am unable to run any command: Below line i have added in bashrc: . ~/.profile
2
votes
1answer
34 views

Bash script for editing action camera firmware values

New to script writing, new to bash, new to firmware modifications, but... enthusiastic as all get out. Here's the link to my camera's firmware. I'm trying to edit and replace the bitrate values ...
3
votes
0answers
64 views

Can I make shell consider NBSP a whitespace character?

This seems like a common issue: you paste a simple command from somewhere into the terminal and it's not being understood by a shell: $ echo test $ zsh: command not found: echo test The reason is ...
0
votes
0answers
26 views

get the stdout and stderr redirection back to terminal

I was running a script in nohup as nohup bash test.sh > logfile 2>&1 & i was tailing to the log file as this script runs for some 2-3 hours. What happened is that i accidentally deleted ...
0
votes
0answers
12 views

Script in Git repository to durably set $PATH

I have a Git repository which needs some setup to build in a way that replicates our CI system. Particularly, we have a complex tool named emerge which does much of the dependency management, and a ...
0
votes
1answer
26 views

Shell script, a function to verifie if FILES=$(ls) contains a file

I am a beginner in shell scripting and I need to find a function, to check if a variable exist in a list in bash. The list is generate this way: FILES=$(ls) and so I need to check if a file is there. ...
0
votes
0answers
5 views

Checking Background Jobs after Using Script to Submit

When I submit a job to the background using the below line, I have no issues using the jobs command to see the status. nohup orca result0000.inp > result0000.out & However, when I use a bash ...
0
votes
1answer
29 views

Bash - make counter print superscript numbers

If I had a script with a counter, printing numbers like this: #!/bin/bash while true; do i=$((i+1)) echo "$i" done; prints: 1 2 3 4 5 [...] how can I make the script print superscript ...
0
votes
1answer
35 views

Create script to manage service

i need your support to create a script necessary to deploy, start and stop a service from one server to the others server. This service is a jar with a properties file. I would create a menu script ...
3
votes
3answers
394 views

How do I rename multiple files by removing everything but numbers?

I want to rename files like: SL Benfica vs. SC Beira-Mar 136.mp4 SL Benfica vs. SC Beira-Mar 137.mp4 SL Benfica vs. SC Beira-Mar 138.mp4 SL Benfica vs. SC Beira-Mar Jogo 074.mp4 SL Benfica vs. SC ...
-1
votes
0answers
36 views

How to set a valuable as an integer [duplicate]

I have a txt file and there has random numbers in it. I try to pick the smallest value from that txt file and set as an integer. I achieved "pick" part but I cannot set this value as an ...
0
votes
1answer
41 views

pass each line in .txt file as argument to python script

I have infinite loop in bash, I need to pass each line in my domain.txt file as argument to python script which can only accept one at a time, when it goes through all lines in domain.txt file its ...
0
votes
0answers
24 views

Purge lines in a file based on age in shell script

I wanted to record the slave delay in mysql server every minute,so prepared a simple script. #!/bin/bash echo "`date` : `mysql -uroot -pXXXXXX -e"show slave status\G" | grep -i ...
0
votes
1answer
47 views

Is there a way to add lines to .bashrc without permission to access?

I have sshed into another computer, on which I’ll be working. In order to access the tools I need, I’m supposed to “go into my .bashrc file” and add two lines: eval 'path/to/file/setup.sh' AND source ...
1
vote
0answers
15 views

Sed works standalone but not in command substitution [duplicate]

When I use the following command in Bash, it works fine: sed -n '/##/{p; :loop n; /##/q; p; b loop}' FILENAME.txt It outputs something like this: ## * Some line Command substitution However, when I ...
0
votes
1answer
30 views

How to define PATH? Without PATH errors

When I write in .bashrc: export PATH=\$PATH:\/usr/local/qc/OPENMPI_3_1_4/bin/ after a reboot, I get this error with any command line: david@doc1:~> less If 'less' is not a typo you can use command-...
0
votes
3answers
55 views

How can I find multiple files in multiple subdirectories?

I need to find a list of files in multiple subdirectories and save the path of each file in a txt file. I have all the filenames in a list in filenames.txt. I am trying to do this: while read -r fname;...
2
votes
1answer
29 views

Is there a limit for the read command?

I'm trying to write a bash script that will let me save a backup code (lots of numbers) in a file. I've finished the script but it's only letting me to save 4096 digits of the code. I tried to do this:...
0
votes
1answer
32 views

Unable to run a bash loop in linux by taking two input files as an input?

Newbie to bash scripting, I made script to automate the program to run on 100 different files, can someone please correct the script. In a directory I had 1 to 100 files with suffix *_R1_sic.fast and *...
1
vote
1answer
34 views

What is wrong with this script that is supposed to test the Collatz Conjecture?

I want to make a script that tests the Collatz Conjecture. More specifically, the goal is to make a script that allows me to enter a positive integer that is not 1, and prints out the final number ...
0
votes
0answers
20 views

How to set a variable with name from another variable? [duplicate]

I'm writing a script in bash and I added these commands that will set names of 2 directories and count of these directories. dir1="name1" dir2="name2" count=2 Then, I made a ...
4
votes
1answer
39 views

How is this script (open-switch/opx-build/scripts/opx_run) passing variables?

Like many bash questions, I'm 100% sure there is an answer but Googling them is challenging. I'm trying to understand the following script: #!/bin/bash # available options export OPX_GIT_TAG="${...
1
vote
0answers
12 views

How can I enable/disable a jail using fail2ban?

We can add a line like this below a specific jail in the jail.local file, and control the jail: enabled = true/false But I think there should be a command to do this, as we've got bunch of "set&...
1
vote
1answer
35 views

Which binary would be run when we have multiple installations?

I wanted to set gsettings as /usr/bin/gsettings so I created an alias. But I am not sure if that works: $ type gsettings gsettings is aliased to `/usr/bin/gsettings' gsettings is /home/linuxbrew/....
0
votes
0answers
26 views

create recursive snapshots with BTRFS

I'm working on a shell script (just with btrfs default tools), which should do recursive snapshots of all subvolumes. My BTRFS looks like that and each directory is a subvolume. In the .snapshots ...
-1
votes
1answer
15 views

How to view all the list that can be viewed by update-alternatives?

Tabbing gives me ls data but i want something to be shown like x-session-manager , x-terminal-emulator and so on. How can i get list what can i set?
0
votes
1answer
29 views

How to convert all text files in directory to one csv

I want to convert all text files in a directory to one csv file. I want the input to the csv to be the text in the text file labeled by the author of the text file found in the filename. For reference,...
2
votes
2answers
59 views

How to split text files by character count in directory

I would like to divide multiple text files in a directory into many smaller text files by a given character count. For example, I want each file in the directory to be divided into smaller text files ...
2
votes
2answers
134 views

how to run `find -exec` inside bash function — problem escaping characters and unexpected end of file

I want to make it easier to run this kind of command: find . -type f -exec sed -i 's|wpp-splash|wpp_splash|g' {} \; so I created a function in my .bashrc to shorten it: function sedall() { find . -...
1
vote
1answer
37 views

How do a dynamically switch parts of a pipe?

I have a script which should execute a series of commands through a pipe. Depending of the arguments passed to the script: Either it encrypts the file, computes its hash, and sends it to a REST ...
2
votes
1answer
32 views

How to make sure only one instance of a bash script with parameters runs?

if I have a deployment.sh, it has two parameters: environment and release version. deployment.sh uat release1 deployment.sh prod release1 I want to make at any time: the deployment.sh with same ...
1
vote
2answers
49 views

How to put updating data in the Bash command prompt?

I am trying to make a prompt that would show the current battery percentage, however if I have my code for setting PS1 in .bashrc the way that it's written then it only checks the data once when the ...
0
votes
0answers
11 views

bash up arrow not working, neither is fzf history

I've been using bash with fzf for quite some time now. At some point I was playing with settings, and I broke either my bash profile, or the fzf or both. At this point, anything that doesn't return a ...
3
votes
3answers
183 views

Set a variable to the result of a division and subtraction command

I am trying to get the difference of 2 dates in epoch form and convert the number back to days: EXPIRYEPOCH=$(date --date="$EXPIRYDATE" +%s) TODAYEPOCH=$(date --date="$TODAYSDATE" +...
0
votes
1answer
40 views

Replace an attribute value with another value in SVG

I have a directory that contains multiple SVG files. What I am trying to do is replace the height="2500" (value of height can be any integer) with height="{{ include.height }}". ...
-3
votes
0answers
19 views

How to find the top 3 process that was started in the last 10 seconds? [closed]

How to find the top 3 process that was started in the last 10 seconds using bash
0
votes
2answers
41 views

Switch all my git repositories to depth 20, to save space?

I know that git clone --depth=20 <repo> is oftentimes much much smaller than git clone. Official docs for --depth. Looks like I've gone a bit crazy with my repos folder, here's the fd piped to ...
-1
votes
2answers
35 views

Convert array into string

I have a string say, test_var=ab_c_de_fg_.txt. I need to store ab_c in one variable (characters before the 2nd _) and de_fg_ in a second variable (characters after the second _ and before .txt), so ...
0
votes
0answers
40 views

grep string that is contained within parentheses [closed]

I'm having trouble with grep strings from the logs. If I have multiple string matching, it won't find any strings after parentheses So grepped log file looks something like this: Jun 26 08:28:00 pzb ...
0
votes
1answer
33 views

How to show bash set -x commands in colors?

I have a bash script which throws 100s of lines. I can see which command doing this using set -x but it's difficult to find it on terminal. If set -x option shows in color I can find it faster. Is ...
2
votes
3answers
25 views

Using regex with IFS variable to split Bash string

I am trying to split a string into an array by any character that is not alphanumeric. Can assign a regex pattern to the IFS variable to accomplish this? I have tried it like so: input="$1" ...
0
votes
1answer
30 views

Command not found despite having just installed it?

As you can see in the screenshot below, I install a command (it's a wrapper for a program called qsiprep), and then try running it, but it says it's not installed...any ideas as to what is happening? ...
6
votes
4answers
883 views

Measuring disk usage of specific file types per each directory (recursively, as a demo for 'du --include')

This is my working code, but I believe it's not optimized - there must be a way to complete the job much faster than this: find . -type f -iname '*.py' -printf '%h\0' | sort -z -u | xargs -r -0 -I{...

1
2 3 4 5
399