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

2
votes
1answer
35 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
31 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
33 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
41 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
24 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
26 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
18 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
45 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
60 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 ...
0
votes
1answer
41 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 ...
2
votes
0answers
22 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
21 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
26 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
25 views

Bash script spawns many new processes of itself [on hold]

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
96 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
31 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
40 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
28 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
27 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
69 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
62 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
340 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
32 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
128 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
33 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
64 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
109 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 ...
3
votes
3answers
57 views

source /dev/stdin doesn't work as expected

Let's start with simple tests that work for me to check that source /dev/stdin can be used at all. # echo -ne 'echo a\necho b\n' | source /dev/stdin a b Now I would like to source an actual ...
-1
votes
0answers
32 views

string bash variable value is not copied to another variable.why? [closed]

I have this code snippet BCR2000_CHAN=$( jack_lsp | grep BCR2000 | grep capture | grep "MIDI 1" | sed -e 's/^.*\[\(.*\)\].*$/\1/' ) BRC2000_CHAN2=$( echo $BCR2000_CHAN | awk '{print $1}' ) ...
0
votes
1answer
41 views

replacing some text in square brakets in bash

I have this string that I get from running jack_lsp. a2j:Arturia BeatStep [28] (capture): Arturia BeatStep MIDI 1 in a xml file, I save the connections state from a previous jack session. ...
8
votes
1answer
265 views

Echoing progress from a background process without hijacking prompt

Consider the simple script hello: #!/bin/bash echo 'hello world!' Now from bash if I try to run this in the background: $ hello & [1] 12345 $ hello world! █ <--- prompt is stuck here until ...
0
votes
1answer
20 views

How to create a file name for the pipeline to delete all files?

So I want to delete all files in my current directory using the following pipeline: ls | sed -rn 's/(.*)\.jpg$/mv -n & \1.jpeg/pi' | sh How to create a file, named so that running the above ...
0
votes
0answers
10 views

I'm calling the Google Analytics Realtime API and getting back a JSON object. I need a script to determine if a value has changed [migrated]

I'm calling the Google Analytics API with an HTML page containing Javascript calls. It returns a JSON object like this: { "rows": [ [ "Submit", "6" ] ] } I'm currently ...
0
votes
1answer
59 views

bash: What is the difference between these two script variants?

(Note: Both of these examples may require GNU or BSD find and may not work as-is with the POSIX "edition" of find). Both of the scriptlets below must be understood as excerpts from way more complex ...
1
vote
2answers
46 views

How can I continuously run a bash script checking if a value has changed?

I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script ...
1
vote
1answer
27 views

Keep service running after ssh session ends [duplicate]

i have an ubuntu-server box to which i connect via ssh. now when i start a service (in this case teamcity) i would like to keep it running after the ssh session ends. right now the service stops as ...
1
vote
1answer
25 views

Shutter Script(s)

When i play some games with wine , i must not change the window , because of that , the game crash or that window are fill of black. im using xfce4 desktop , when i press "PrintScreen" key from ...
2
votes
1answer
44 views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
1
vote
0answers
18 views

How keep the correct output line of command [duplicate]

I need to keep the correct output of avconv command: filetype=`avconv -i first.mp3 2>&1` echo $filetype the results is an incorrect output. like this: avconv version 11-6:11-2, Copyright ...
-3
votes
1answer
21 views

redirecting output of command to variable

Easyly: export a=$(avconv -i "first.mp3") or export a=`avconv -i first.mp3` output of avconv goes to stdout and does not to variable a
-1
votes
2answers
137 views

delete files having a certain pattern in their names

I want to delete all files that have two numbers and a dot in beginning of their names for example: 01. abc 02. xyz
-1
votes
2answers
34 views

understanding sed, awk and curl interaction extracting ssh URL information from github page

I needed to pull every public repo in a user's GitHub account. To do this I got the API output of https://api.github.com/users/SOMEUSER/repos This is what I came up with. To extract the ssh_url line ...
1
vote
3answers
33 views

TAR Files: Move Files From Subdirectories to Main Directory

I've been trying to use this code: find documents -maxdepth 1 -type f -print0 | xargs -0 tar cvf documents.tar.gz to create a backup of the directory documents. The directory has the structure: ...
1
vote
2answers
74 views

How to rename file in bash script one by one

I have loads of files which look like this: data1.csv data2.csv . . data(n).csv My use case is that when I will call my script it will change data1.csv to data.csv and remaining files as it is and ...
2
votes
4answers
164 views

Extracting the second word from a string variable

I have a string "rtcpOnNbActive true" stored in a variable x. I want to extract "true" as substring and store in a variable. How can I do this?