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

1
vote
3answers
31 views

Print array line by line in a here doc

I currently have the following here doc message=`cat <<-EOF Test data: Test data 1: "${Test_data_array[@]}" EOF` echo "$message" Is there a way to get the array to display multi-line per ...
4
votes
4answers
262 views

files greater than a average size of directory?

how could I find all the files and directories with size larger than or equal to the average file size of the current directory?
3
votes
2answers
57 views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, i.e. read -d '' <variable> script block ...
1
vote
1answer
41 views

SIGINT handling differences between bash 3 and 4

I have a script which works great in bash 4.3, but gives me unexpected behavior with bash 3.2. Here's a simplified version: set -o errexit -o pipefail task() { local name=${1} local ...
3
votes
2answers
63 views

What does “if echo $line | grep -F = &>/dev/null” do?

I'm not sure what the following line does in a bash script: if echo $line | grep -F = &>/dev/null then ... I know &>/dev/null is short for >/dev/null 2>&1, I'm not sure, ...
19
votes
3answers
867 views

Why does bashrc check whether the current shell is interactive?

On my Arch install, /etc/bash.bashrc and /etc/skel/.bashrc contain these lines: # If not running interactively, don't do anything [[ $- != *i* ]] && return On Debian, /etc/bash.bashrc has: ...
1
vote
2answers
69 views

BASH how to save output of rm with timestamp?

I nearly have this working, This is a script that will run in CRON to keep the latest 10 backups, and remove anything else, I want to log this to keep track to make sure all is in good order, I have ...
3
votes
1answer
57 views

Is it possible to save the output of a previous command on file?

Quite often, I'm in the following situation: I launch a command on bash (that takes lot of time to be processes) and I get a long output, which doesn't fit into the terminal and it can't be read ...
1
vote
3answers
43 views

bash multi-threads help require

I have a list of IPs and I need to check them for opened ports using nmap. So far, my script is like this: #!/bin/bash filename="$1" port="$2" echo "STARTING NMAP" while IFS= read -r line do nmap ...
0
votes
2answers
36 views

Input redirection using command and options

I am trying to write a script that takes in 2 parameters - program name and optional flags. I am trying to execute the program command on an input_file and store the output in the output_file. ...
0
votes
3answers
50 views

piping with grep

I want to search "C" in the grades column inside the file "input.csv": roll,name,total,rank,grade 001,A B,78,23,C 003,F YZ,100,1,* and what I'm trying is: cut -d"," -f4 input.csv | grep "C" ...
2
votes
1answer
22 views

Repeat based off user input OS X

I am creating a script which asks a user to enter a message then how many times they would like to display that message. This is what I have so far. message.sh #!/bin/bash echo -en "Enter a ...
0
votes
1answer
11 views

linefeed in bash script - to email

I am doing printf to a logfile and having that logfile send through mailx, however, it seems that the linefeed "\n" are not recognised or captured in the mail. Snippet of script as below (notice the ...
2
votes
3answers
63 views

log out via shell script

I am doing some operation via shell script. If that script is successful, continue else logout of the current user. I am unable to find a way to logout of current user. I tried to use exit but seems ...
39
votes
3answers
5k views

How does `yes` write to file so quickly?

Let me give an example: $ timeout 1 yes "GNU" > file1 $ wc -l file1 11504640 file1 $ for ((sec0=`date +%S`;sec<=$(($sec0+5));sec=`date +%S`)); do echo "GNU" >> file2; done $ wc -l ...
5
votes
2answers
39 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
0
votes
1answer
24 views

problem in login with default /bin/fish shell in gdm

I set my user default shell to fish. /etc/passwd file: mlibre:x:1000:1000::/home/mlibre:/bin/fish and then, in GDM I can't login with my user (mlibre). GDM prints some error. Then, I changed back ...
2
votes
2answers
36 views

Find commands/function whose name matches a value

I am looking for some command e.g. match ls which should match commands like ls, alsa asls,.. and return them. I preferably want it to cover both all commands and defined functions. Is there a builtin ...
0
votes
1answer
17 views

Arrays with spaces: do groupinstalls from script [duplicate]

I know, the group names that contains spaces has to be enclosed by quotes and they are, still this does not want to work out as I would expect it: export instdesk="xterm java-1.8.0-openjdk xrdp ...
0
votes
1answer
28 views

How to stop an infinite loop function called with myFunc &

In my bash script, I have a function that does one certain task in an infinite loop. To allow for the next part of my code to run at the same time, I run it with myFunc &. How can I kill this ...
0
votes
1answer
19 views

Bash script hangs on specific input

I am trying to write a simple script which does something if the first parameter of the input is equal to the -r string. But whenever I try to run this file, the program hangs and I have to terminate ...
3
votes
4answers
67 views

Sticky entries in shell history

Is there a way one could make some commands "sticky" in a shell history? I want to save some favourite commands that would be searchable with Ctrl+R, like the rest of the history, but they should ...
12
votes
1answer
125 views

evaluation of arithmetic expansion in bash

The following line creates file_c-6.txt but outputs 5: $ i=5; ls file_a-${i}.txt file_b-${i}.txt > file_c-$(( ++i )).txt; echo $i 5 $ cat file_c-6.txt file_a-5.txt file_b-5.txt If one removes ...
1
vote
1answer
24 views

Breaking out of a loop, return to start of loop with correct value of variable

I am sending processes to a server, but I only want a certain number running at a time. Thus I loop which checks how many jobs are running and only submits new one if the current amount of jobs do not ...
0
votes
2answers
48 views

How can I filter out current directory ('.') in bash?

I'm currently trying to write a little script to convert all the flac files to mp3 files. However, I ran into a bit of a problem when trying to set up recursion down into all my music folders - the ...
-2
votes
2answers
52 views

How to use this script [closed]

#!\bin\bash for i in `seq 1 1000`; do wget -q -O quotes http://www.quotedb.com/quote/quote.php?action=random_quote; cat quotes>>final.txt; done I got this script from one website but I don't ...
0
votes
1answer
41 views

set date time from user input in shell

I am creating script to check RTC working & for that first I am getting the date & time from user input in yyyy mm dd hh:mm:ss format. read -p "Enter the date:" val echo $val date -s "${val}" ...
2
votes
1answer
22 views

Error exit script from within command substitution

If I have a function: myfunction() { [ -d somedirectory ] && [ "some other condition" ] || { echo "error" >&2 ; exit 1; } global_var=somevalue } And I call it from within another ...
0
votes
0answers
18 views

how to interpolate a string in this CURL call

In Bash, I have this curl call: curl -d 'user[email]=jj@jk.com&user[password]=abc123' http://domain.com/arc/v1/api/users and would like to interpolate a UNIX timestamp call to add the current ...
0
votes
1answer
38 views

opening multiple tabs in firefox using a one-liner bash script [duplicate]

I am on CentOS 6.6. I have a program that runs analysis and outputs its data in html files. The file structure is dir1/dir1.html dir2/dir2.html dir3/dir3.html I want to open all three html files ...
0
votes
1answer
31 views

What are conditions I can check for detecting error in downloading using bash?

I want to continuously download a link until it successfully downloads, #!/bin/bash while [ some_condition ]; do curl my_url # or vagrant add my_vagrant_url ...
0
votes
0answers
13 views

How to generate total size of files from each unique source in bash

I have a large number of directories which each contain files with the format unimportant_data_here_source_date.gz I want to calculate how much data came from each source. That means figuring out ...
1
vote
0answers
34 views

Bold and Underline using echo with email

I am using a script that emails me a particular status report. The script sends me the contents of several files. I am using echo to provide a heading in the email that is used to differentiate ...
-2
votes
1answer
30 views

Add one text to multiple files using bash [closed]

I have many files with the extension .com , so the files are named 001.com, 002.com , 003.com , and so on. And I have another file called headname which contain the following information: abc=chd ...
2
votes
1answer
71 views

How to get filenames when using find and sed

I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified. This is how I am finding and then using sed: find . -type f -a ...
0
votes
1answer
38 views

Compare a certain lines from multiple documents

I want to compare a certain lines in a multiple documents. I tried using diff and comm, but the conditions are these, the documents are in a different working directory/folder, I could use a ...
1
vote
1answer
44 views

Bash - Running a bash script from within a ksh script

I am on RHEL 6.7 and have a korn shell script that does check pre-reqs, prepares the system for rpm install's (creating directories if they are not already that are required by the product), stops ...
1
vote
1answer
24 views

grep restart script if not running

Hi guys i'm running into an issue here that I need to have a nohup php script run in the background and make sure it's always running and restarted if it crashes. I run the following bash script using ...
-1
votes
2answers
34 views

ssh linux to mac inside and outside lan

Hi this is my first post and I was wondering if anyone can help me? I have ubuntu on my home pc and I want to be able to ssh to a macbook. When they are both on the same wifi network it's no problem, ...
3
votes
2answers
45 views

How to write a “compose” function of bash pipelines with named pipes

This page details psuedocode for creating a compose function that takes n commands and executes them in a pipeline: We program a command compose such that compose cmd1 cmd2 ... cmdn behaves ...
4
votes
1answer
66 views

Why is subshell created by background control operator (&) not displayed under pstree

I understand that when I run exit it terminates my current shell because exit command run in the same shell. I also understand that when I run exit & then original shell will not terminate because ...
0
votes
1answer
30 views

Can someone please explain this error I'm getting in my script

I'm trying to create a script which I can set as a cron job which adds all my dotfiles to a folder I've set up as a github repo then push them every evening. My script is the following. cp ...
0
votes
1answer
48 views

Using sed on files with certain extension inside shell script

I am trying to use sed to find files with certain extension and then replace occurrences of a certain string with another. No directory mentioned using current directory *.h sed: can't read *.h: No ...
0
votes
1answer
39 views

Check how a script was started

I'm making myself a few "helper" scripts, and the first one is to install NodeJS. The first issue I've just solved, was getting source ~/.profile to persist changes. I found out running . ...
1
vote
0answers
50 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
4answers
51 views

Change dir from script without a “shell procedure” or “sourcing the script”

I know what I can make a shell procedure or source the script instead of running it to cd the shell I am using. What I want to know is there any way to cd the "parent shell" (not sure if that is the ...
0
votes
1answer
52 views

ssh authentication and remote command output's redirection

I need to run a remote capture on a host via ssh and to authenticate twice, but the second prompt is being redirected. ssh -t user@host "sudo tcpdump -s 0 -n -w - -U -i eth0 not port 22" > ...
0
votes
0answers
19 views

Direct stout & stderr to custom log file using logger

Im trying to output stout & stderr of a script to a custom log file while still displaying it in the console as well. I've looked at examples which use tee as well, but would like to have the ...
3
votes
1answer
66 views

Bulk downloading PDFs

This may/may not be possible using bash happy for a suggestion in Python if there is one. But I would like to download all the PDFs/ePubs from the following link https://mises.org/library/books ...
1
vote
1answer
59 views

Infinite loop in bash

I've 672 files in local directory, filenames are like: boutique-*_20160116hh0000.csv, general-tgbt_1_20160116hh0000.csv, where hh - hours' number and (for instance, boutique-a13_15_20160116060000.csv, ...