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.

learn more… | top users | synonyms

1
vote
0answers
3 views

Clear / Reset console at start up

I'm using Bash Windows 10 Bash (WSL). I need to put echo -e '\e[9999H' at the beginning of my .bashrc script in order for it to have 24-bit colors in ConEmu. This unfortunately makes my prompt start ...
1
vote
1answer
10 views

Trap output of a function, but let it exit

Suppose we have fct defined like so: fct() { echo words read -n1 x [ $x == q ] && exit } Calling fct works as expected, but if you need to trap its output, var=`fct`, exit does not ...
3
votes
1answer
59 views

Meaning of '2> >(command)' Redirection in Bash

A while ago I made a script and I added some logging around it, but I forgot how the redirection for the logging works :-( The gist of it is: #!/bin/bash LOGFILE=/some/path/mylogfile ( # here go ...
0
votes
2answers
20 views

Break out of while loop on error

I have a while loop in this form: while :; do performTask1 || break performTask2 || break performTask3 || break ... performTaskX || break done Basically, I want to break out of the ...
1
vote
2answers
34 views

Extracting string up to first digit in Bash

I would like to find a straightforward method to extract the portion of a string up to where the first digit appears (possibly using regular expressions instead of traversing the string character by ...
0
votes
2answers
17 views

Usage of consecutive variable names in a script

I want to do some simple calculations with variables in an script.sh, in the same directory there is a folder called New Folder2. So, I want to enter into the folder and save a text file. The script ...
0
votes
3answers
32 views

Integer expression expected in if statement

I have a small shutdown script, if the Mac runs over 24 hours it will shutdown. I'm not really experienced in bash scripts, but I did this: !/bin/bash #Maximum number of days to be up max=1 #Get ...
0
votes
1answer
32 views

How do I store bash env vars in array then access/modify?

I want to store environment variables in a bash array, and then use them in cases where I perform the same operation on all of them (unset, export an so on). For example, if I want to print all env ...
0
votes
0answers
26 views

Why my script is not terminating after I exit the shell? [duplicate]

As far as I know if we are using & after a command or script, it will exit once the shell is terminated or logged out. So I have a simple infinite loop script and I am executing it like :: [root@...
1
vote
0answers
24 views

Command to force user to enter password - RHEL/Centos

I am trying to use Ansible to create a new user and set a password for this user. I want to test if the password was actually set. I figure a command that forces me to enter the user's password would ...
0
votes
1answer
26 views

Why does this echo call overwrite existing text?

Consider the following CSV file: jdbc.driverClassName,oracle.jdbc.driver.OracleDriver jdbc.username,kshitiz It has to be transformed into: -Djdbc.driverClassName=oracle.jdbc.driver....
2
votes
2answers
33 views

count lines matching string in each subdirectory and their subdirectories

In each subdirectory of my current directory, I would like to print the number of line-matches against a string for all files in the subdirectory and its subdirectories. For example, if I have cat /...
0
votes
1answer
25 views

why doesn't eval declare in a function work in bash?

Tracking down strange behavior a bash script resulted in the following MWE: set -o errexit set -o nounset set -x my_eval() { eval "$1" } my_eval "declare -A ASSOC" ASSOC[foo]=bar echo success ...
1
vote
1answer
32 views

Why can't I execute this script?

I am trying to execute a script to determine its system running time and potentially fix its problems. If I type: {hostname@bankofamerica]$ ./xx-xxx-xxxxx.sh [sudo] password for hostname: _ It ...
1
vote
2answers
25 views

combining 3 separate arrays to one multidimensional array in bash

Is possible to create multidimensional arrays in bash scripting? These are my 3 arrays: arrayCITY=( NewYork LasVegas Detroit ) arraySTREET=( RoadStreet TreeStreet HighStreet ) arrayNUMBER=( 20 455 ...
-2
votes
0answers
29 views

Shellshock attack issue

I'm having an issue with practising a shellshock attack on a virtual machine , I'm trying to get it to locate and print a password file but every time I run it using curl in terminal it seems to only ...
0
votes
0answers
6 views

Cannot redirect to a webpage after ssh tunnel creation in cgi context

I have this script named test.cgi under my /cgi-bin directory: #!/bin/bash /usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -M -S /tmp/my-ctrl-socket -fnTN -L 172.30.26.14:...
-3
votes
0answers
27 views

Speeding up Linux scripts in vim [on hold]

I am trying to speed up our .sh files that are insanely slow. What are some number of ways to run the whole script or a subset of scripts in a faster and robust way? Thank you! and I really need HELP!...
2
votes
2answers
39 views

Retrieving files with grep that contain !#abc

I'm trying to display files that contain !#abc I tried like this grep -l '!#abc' but it doesn't work. Why? Also, when I try something like echo "#!a" it retrieves echo "#alias". Can someone, ...
0
votes
1answer
30 views

Find and remove directory from bash

#!/bin/bash # error handling function error_handler() { echo "Error occurred in script at line: ${1}" echo "Line exited with status: ${2}" } trap 'error_handler ${LINENO} $?' ERR set -o errexit ...
0
votes
2answers
66 views

How do I call a script with a wildcard pattern and two more arguments?

I have this code to rename a bunch of files: #!/bin/bash for file in $1 do mv -i "${file}" "${file/pattern/replacement}" done How do I replace "pattern" and "replacement" with $2 and ...
0
votes
2answers
23 views

Loop until grep does not find the text in a file

I have a file named file.txt. The content of the file is as follows sunday monday tuesday I wrote the below script and it loops just fine if the grep cannot find the pattern that was mentioned ...
1
vote
2answers
48 views

Piping a non-constant amount of commands [on hold]

piping commands is fairly straightforward once the number of commands n is fixed. For example (n=2) echo Hello | grep llo But let's say the number of commands may vary. It will only be known at the ...
1
vote
1answer
18 views

Wget batch download and save failed links

Is it possible to use wget to download multiple files from a text file and have it save the URL of any failed downloads to a different text file? I use wget bash scripts to download files from a text ...
3
votes
1answer
50 views

Can I specify a custom command before launching interactive bash session? [duplicate]

Please note: Although this question is essentially the same as this linked question, I did not mark it as "solving my problem" because the answers provided there are not very satisfactory. The answer ...
1
vote
2answers
47 views

Cron work is not working

I'm using debian distribution. I have a cron job in /etc/cron.d/ directory, It's called testuoju.sh. It looks like: 34 * * * * bash /var/www/html/script/testuoju.sh testuoju.sh file in /var/www/html/...
0
votes
0answers
44 views

Why won't a case statement work in a function? [on hold]

I wrote a bash script which kept on defaulting to the deafult case option despite the parameters which were passed. That case statement was nested inside a function. Upon removal from the function to ...
1
vote
1answer
41 views

How do I wait for background jobs in the background?

I have the following problem: $ some_command & # Adds a new job as a background process $ wait && echo Foo # Blocks until some_command is finished $ wait && echo Foo & # ...
-1
votes
0answers
34 views

Translating Bash code to Python

I'm trying to "translate" this bash code into python and I need a little help with this.. #!/bin/bash dpkg-scanpackages ./debs > Packages bzip2 -fks Packages So what this code do is checking and ...
-3
votes
1answer
28 views

Not able to Run cd command with restricted user!

I have restricted a normal user to limited commands using rbash, now am not able to cd (change directory) to other directory,can someone help me how can i run cd command with restricted user, please ...
0
votes
1answer
43 views

Piping cat to sendmail not respecting new lines

I have a script which runs a few sanity checks, outputs the results to a file which is then concatenated and piped to a sendmail function as so: { echo "$headers"; echo; cat health_check.log; } | ...
0
votes
1answer
22 views

bash file execution [on hold]

On OSX El Capitan. I wanted to build my own script which I can call anywhere meteorB.sh The steps: create the file and put the commands in it. chmod u+x of the file and move it to ~/Documents/...
0
votes
1answer
53 views

Command works when copied and pasted but not in a bash script?

I'm trying to pass a windows command into a linux netcat shell and then read back the output. So far I have: cat <( printf 'ipconfig\n' )| nc -v 137.148.70.243 443 Which when copied and pasted ...
2
votes
2answers
48 views

error in while loop with sed

I have a file I want to parse: mmu-miR-15-5p/16-5p/195-5p/424-5p/497-5p 0610007P14Rik mmu-miR-326-3p/330-5p 0610007P14Rik mmu-miR-326-3p/330-5p Lmir mmu-miR-15/16/195/424/497 0610007P14Rik ...
0
votes
1answer
21 views

Check if multiple directories exist with bash script [duplicate]

I have a file with a list of directories and I need to find out if they actually exist on the system. It's quite a large list so I'd like to figure out how to automate the check. The file is ...
2
votes
2answers
26 views

Multiple commands with quotations after SSHing

I have a server I have to ssh into with many commands which feature the use of variable assignment and consequently a lot of quotation marks. If we consider the script: ssh user@host "kinit -k -t /...
3
votes
3answers
502 views

Put two commands after an ||

I'd like to check to make sure a handful of commands are available. If it's not, I'd like to print an error message and then exit. I'd like to do this without checking variables, because it's a small ...
0
votes
0answers
25 views

Insert row by bash script to mysql database [on hold]

I try to add a row to an mysql database by using a bash scrip the query that i want to execute is like this: INSERT INTO `Tempdb`.`TempTB` (`TempValue`, `DateTime`, `RPIid`) VALUES ('22',NOW(), '8');...
0
votes
2answers
37 views

How to extract and parse commands of shellscript to file?

I have the following program in Shell Script: #!/bin/sh max=9 for i in `seq 1 $max` do sudo -u ${USERNAME} heroku config --app mws-usp-app0${i} done max=50 for i in `seq 10 $max` do sudo -u ...
1
vote
3answers
37 views

Remove a specific portion of line

I have a csv file that has many lines of timestamps in following format HH:MM:SS:MS For example: 00.00.07.38 00.00.08.13 00.00.08.88 The hour is not relevant to me so I would like to cut it ...
1
vote
2answers
29 views

send to log and display on console

I have a small test script here, it has error handling. I would like all STDERR and STDOUT to be displayed on the console (which they currently are) AND made into a log file. #!/bin/bash # error ...
1
vote
0answers
28 views

Check for user activity in a Bash script

I'm writing a script (to be run on a multipurpose desktop machine) in which I want to check that there is no user activity. The non-activity would be defined as: Any user using GUI has not been ...
0
votes
4answers
46 views

How to use as argument the characters + , - , x , / in a script [duplicate]

I am trying to write a script I will call calc.sh that does basic calculations using the arguments for the script ( $1, $2 and $3). For instance I'd like to get 2 as result for ./calc.sh 10 / 5 My ...
4
votes
3answers
52 views

Is it possible to hit Shift-k and open a manual for a command in Bash?

In Vim you can hit Shift-k and open a manual for a string under the cursor. Is it possible to configure Bash this way as well (when using set -o vi)? For example: # '|' represents the position of a ...
0
votes
1answer
47 views

Yet another syntax error near unexpected token `(' [on hold]

This one different from the others as: I'm invoking bash (not sh) in the shebang: #! /bin/bash I'm running it with ./ File permissions are correct: 755 The line in question is: formattedTIME=`awk '...
8
votes
3answers
1k views

What is the difference between && and | in bash script?

Let's take the two lines below which give us two different results. p=$(cd ~ && pwd) ; echo $p p=$(cd ~ | pwd) ; echo $p How do the two differ?
0
votes
1answer
29 views

How to include $ sign as string?

I want to create multiple files with a common template, problem is there have "$(variable)" in the template, which should be written with $ sign. for example, I want output is $job_ID from echo "...
1
vote
1answer
18 views

Rsync directory filtering out files and retaining edge cases (e.g. names w/ hyphen (-) chars)

I have a test folder with the following structure: "driveA" - "bar - foo" - "fileBarFooA" - "fileBarFooB" - "fileA" - "fileB" - "fileC" - "folder.A" - "fileAA" - "fileAB" -...
1
vote
2answers
51 views

Saving command output to a variable in bash results in “Unescaped left brace in regex is deprecated”

Errata: Similar questions about this have been asked but after searching this for a few days there appears to be no answer to this specific scenario. Description of the problem: The second line in ...
4
votes
1answer
44 views

How can a shell script avoid the SIGPIPE that would be caused by use of closed file descriptor?

A shell script can lose its standard and other file descriptors if the other end goes away. One way this can happen is by terminating a ssh client used to launch the script: $ ssh localhost test ^C ...