Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

3
votes
2answers
16 views

Append unix timestamp to files with space using a script

This script works fine for all files recursively as well but it does not name files that has space in between. For example it throws error for the files "this is a test.txt" or "test file.txt" Any ...
3
votes
2answers
39 views

bash add path to handle some files

inside ~/mp3 I've some mp3 files. My script: #!/bin/bash br=80 for a in $1*.{wav,mp3} ; do ffmpeg -i "$a" -ar 44100 -ab $br "$br""_tmp/${a%.*} ["$br"].mp3" ; with $1 add the path: myscript.sh ...
1
vote
4answers
59 views

Executing a command within `if` statement and on success perform further steps

I was trying to execute a program which will create a directory on the basis of a complete path provided to it from the prompt and, if the directory already exists it will return an error (for ...
-2
votes
1answer
15 views

bash for loop to run ruby scripts

I'm trying to run several ruby scripts from the command line. Here is my code so far: for i in {1..59}; do $("ruby sample$i.rb"); sleep 10; done The purpose is to test all these scripts quickly, ...
0
votes
0answers
8 views

How to permanently enable scl CentOS 6.4?

I installed a newer version of devtoolset (1.1) and was wondering how I would go about permanently setting these to be default. Right now, when I ssh into my server running CentOS, I have to run this ...
3
votes
4answers
66 views

How to swap entire html blocks in multiple files with sed

I have tons of html pages with a simlar content as follows: <div class="wrapper"> <div class="aaa"> ...lot of html1 here </div> <!-- end aaa --> <div class="bbb"> ...
0
votes
1answer
22 views

kill parent and child because endless loop

I have a process run by cron every hour. Such process calls another one (not sourced), ie: ./childProc.sh (Not sure if this detail is important) Because of an endless loop in child process (which ...
2
votes
1answer
54 views

Is replacing a particular line in a file through a bash script possible in VIM or EX?

I would like to modify a particular line, say line 5, in a file by using the EOEX construct how can I achieve my aim? The code snippet that I use to achieve my purpose is as follows: #!/bin/bash ...
1
vote
2answers
28 views

Replace user shell from dash to bash [duplicate]

Everytime I use my terminal, I am always put into the dash shell instead of bash. Is there any way to change this even just for my user only? Tried apt-alternatives but setting the default shell can't ...
5
votes
2answers
160 views

Bash limiting precision of floating point variables

In Ubuntu 14.04.1 LTS 64-bit bash I am declearing floating point variables by multiplying floating point bash variables in bc with scale set to 3; however, I cannot get the number of digits after the ...
0
votes
2answers
32 views

Bash Script Parsing Argument not working correctly

i have the following bash script (taken from FFmpeg) #!/bin/bash ################################################################################ # # Script name: MultiMedia Concat Script (mmcat) # ...
2
votes
2answers
28 views

Bash globs as non-file arguments. Example: apt-get remove pkg-*

I know * and other glob patterns are transformed into words by pathname expansion, based on the current working directory. Hovever, some commands seem to use them for non file arguments. For example, ...
2
votes
1answer
33 views

Bash update list of running jobs with ps

I need to run in parallel a set of computationally intensive tasks. What I was trying to do is to maintain a list of pids corresponding to the running jobs and update the list of running jobs with ps ...
2
votes
2answers
44 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
-1
votes
2answers
9 views

OSX bash. grep for string “--version=”

How can I search for string --version= using grep in OSX bash? When I try something like this: grep -rI --exclude-dir=out "--version=" . I get grep: option `--version' doesn't allow an argument ...
2
votes
1answer
35 views

Shell expansion and positional parameters

I want to make an script equivalent to zgrep or bzgrep, but using tar. I made two very similar attempts and I would like to know if there is a better one and if they could be improved or they are ...
0
votes
0answers
20 views

run -i vs run -it?

I am using boot2docker on windows. I tried the following commands docker run -i centos /bin/bash docker run -it centos /bin/bash Both provides same kind of execution. I read -i is interactive ...
1
vote
2answers
64 views

Is there a reason to quote the exit status $? variable?

I was looking at Google's style guides for their bash scripts, and saw that they quote the exit status variable $? here. if [[ "$?" -ne 0 ]]; then error_message fi I thought return values are ...
2
votes
1answer
42 views

How to count the number of occurrences of a number larger than x, from every column?

I'm trying to figure out how to count the number of occurrences of values that are greater than some number (i.e. 0.1) in each column and then print that value out for each column. Here would be some ...
1
vote
2answers
34 views

Read Command : How to verify user has typed something

I am a beginner in Bash so please bear with me. I'm trying to create an if else statement to verify that the user has entered something. If they have it should run through the commands, and if not i ...
1
vote
1answer
38 views

let script find path of itself

I want to have a bash-script discover its own path. The background is that I have a script called process_scanned_text.sh, which itself uses the script curves. I put curves in the same directory as ...
2
votes
3answers
57 views

Execute command within variable

I'm trying to execute a command, stored within a variable: cmd="grep -i \"word1\" filename | grep -i \"word2\"" eval $cmd But when I execute the script I get the errors: grep: |: No such file or ...
3
votes
2answers
26 views

How to find a file with partially specified path?

I am trying to find all my .txt and .csv files in my backup (Apple's time machine). The structure of the backup directories is like this: /machine name/date/Macintosh HD/ The above contains all ...
-5
votes
0answers
22 views

How can I using array to display webpage? [on hold]

I need help please this is my code . If the user press b will display the URL in array i--. How can I write a command for option b that's make array i--?
3
votes
2answers
40 views

forward function and variables into sudo su - <user> <<EOF

I have declared functions and variables in bash/ksh and I need to forward them into sudo su - {user} << EOF: #!/bin/bash log_f() { echo "LOG line: $@" } extVAR="yourName" sudo su - ...
0
votes
1answer
21 views

Why doesn't this tee with process substitution produce the 1st and chosen lines? [duplicate]

What I want is printing the output the first line ( table head ) of ps aux and the grep result. After search, I come up with following. ps aux | tee >(head -1 > /dev/tty) | grep mongo But I ...
1
vote
3answers
55 views

looping a command without waiting for the first run

I want a better way to do this, mostly for command line use: while sleep 60; do mysql -e 'show processlist'; done This is better than: while mysql -e 'show processlist'; do sleep 60; done ...
0
votes
4answers
64 views

Time calculation [on hold]

I have a text file containing flight times, hours and minutes one per line: eg 8 minute(s), 28 second(s), 870 milliseconds 19 minute(s), 24 second(s), 398 milliseconds 18 second(s), 876 milliseconds ...
1
vote
2answers
59 views

How does bash's arithmetic work?

read num1 2 read num2 5 echo "$((num1+num2))" 7 echo "$(($num1+$num2))" 7 I referred this. I don't understand how the above both expressions yields same result? Please explain. echo ...
1
vote
1answer
30 views

Is there a /dev/pts alternative on Mac OSX?

I'm attempting to determine how many terminal windows are open, as described in this Q&A answer. However there doesn't seem to be a /dev/pts on Mac OSX. Is there an alternative to this?
0
votes
1answer
27 views

Expect script buffer output not showing

How can I get the command output from the buffer? Current'y it's just saying "(buffer). Here is my script and debug output: #!/bin/bash -x while read p; do echo $p { /usr/bin/expect -d << ...
-2
votes
0answers
11 views

When to use a script, alias, or function [duplicate]

How do I know if a task I do regularly should be simplified with a script, alias, or function? Is there any advantage to one over the other?
2
votes
0answers
30 views

tmux ignores the configuration files

tmux ignores the configuration files: both /etc/tmux.conf and ~/.tmux.conf. Even I pass the path to the configuration file, using tmux -f path/to/tmux.conf it still doesn't load it. The configuration ...
1
vote
1answer
26 views

Bash script spawns many new processes of itself [closed]

The script that I am working on right now is used to save data from 3 columns into three different arrays, which will be used for a different part later. Right now the script callconv.sh looks like ...
3
votes
1answer
111 views

bash permission denied but sh works

A little script of mine on a mounted windows partition refuses to be executed directly (shebang is #!/bin/bash), but interestingly calling it with bash/sh works. The script is simply a collection of ...
1
vote
2answers
34 views

do not show error if file doesn't exist on copy, without sending to dev null

I want to avoid my script posting an error if I try to cp a file that does not exist. However, I would like error messages to print out for any other error, such as insufficient permissions. This ...
1
vote
1answer
45 views

What is Best Practice for running PHP in background?

When running the following on the command line it will be suspended until I issue the fg command: /usr/bin/php -r 'phpinfo();' & This is the case regardless if the PHP code is contained in a ...
1
vote
1answer
32 views

why does grep '\;.' expand to grep '\''\;.'\''' when executed over ssh?

$cat test.sh ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'" $bash -x test.sh + ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c ...
2
votes
1answer
29 views

HISTTIMEFORMAT syntax

There are many bash guides that include adding lines such as HISTTIMEFORMAT='%d/%m/%y %T ' or HISTTIMEFORMAT="%F %T " to ~/.bashrc or /etc/bash.bashrc. There's always a space before the final quote. ...
3
votes
3answers
54 views

Redirecting stdout to terminal and file without using a pipe?

I have code, that goes something like this: #!/bin/bash VAR=0 func() { VAR=$((VAR+1)) echo 'Logging information.' } func 2>&1 | tee 'log.txt' echo "Should be 1: ${VAR}" When ...
1
vote
1answer
28 views

Process id of a command ran by an user

Consider i am running just some basic command.. ls Now would the above command have a pid, when it was getting executed? If yes, then how can i determine that pid? when i try echo $! right ...
3
votes
2answers
72 views

Am I hitting a race condition in bash?

I have a script which compares the output of a command with the output of the same command as it was ran previously, it works most of the time, but every now and then it doesn't work as expected. ...
1
vote
2answers
66 views

How do I expect 'echo -e “? \c”'?

I'm an absolute newbie to the UNIX world and have been asked to write a script that interacts with another one - but I'm stuck. The script that I interact with echos the following and I need to send a ...
4
votes
3answers
342 views

How can I start a process with any name which does nothing?

I want to start a process that does nothing but is still running. Say I start a process called sadhadxk, and when I run pgrep -x "sadhadxk" I will get the PID number back, like any normal process ...
1
vote
2answers
39 views

script to add users to otrs

Im looking for a fast way to import customer users into otrs (ticket system) I have an export from Active Directory with: firstname lastname password email username There is a script in the otrs/bin ...
8
votes
2answers
139 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
3
votes
1answer
35 views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
3
votes
4answers
65 views

Inner loop conditions shall depend on outer loop run

How can I build an inner loop such that the loop condition depends on the outer loop run? My very situation does probably not matter for the code I am looking for, but here it is: I have a crawler ...
2
votes
2answers
69 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
4
votes
2answers
111 views

Find and create empty files with the same name in another location

I want create empty files with the same name, but in another location. Is it possible? find some files use only filenames touch an empty file in another place Something like this: find . -type f ...