Bash is the shell from the GNU project. It is the standard shell on Linux and often available on other unices. If your question applies to all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

6
votes
4answers
279 views

Check if $REPLY is in a range of numbers

I'm writing a shell script for Linux, using Bash, to translate any video-file into a MP4. For that, I'm using avconv with libvorbis for audio. Inside my script, I have a question for the user : ...
3
votes
1answer
94 views

Is there any drawback to using “grep -E” instead of plain “grep”?

I understand that GNU grep without -E uses basic regex and that grep -E uses extended regex. Is there any harm in using grep -E even for situations that would work with plain grep?
3
votes
1answer
98 views

bash command line editing (Emacs shortcuts)

When writing a command on the bash command line, I can use CTRL+w to delete a word backwards, or ALT+d to delete word forwards. The problem is, that these two shortcuts are not exactly complementary: ...
5
votes
1answer
101 views

Loop through binary data chunks from stdin in Bash

I'm looking for something like while IFS= read -r -n $length str; do ... done but for binary data. Is it possible to do this using dd or other tools? Is there some technique to make these tools able ...
0
votes
0answers
14 views

Boot Halts if Time if Reset

I have an old powerbook g4 with a dead battery & I am trying to run ubuntu 10.04 on it. Whenever the power cord gets unplugged the date gets set back to Dec. 31st 1969. Apparently when you ...
1
vote
2answers
77 views

Running a bash script as root prevents asynchronous execution?

The script below get's executed differently if run as a root user. #!/bin/sh gnome-terminal -x sleep 10 echo 'Why must I wait for sleep to finish?' If its run as a regular user, message is ...
2
votes
2answers
103 views

wget to get list of files

im using wget in a bash script to get a list of files from a website, the files are sequential and in the format http://site.com/00001.csv etc, is there a way to terminate/end the script when I hit ...
5
votes
4answers
144 views

Can a program next in a pipeline see the exit code of the previous program?

I would like to make a pipeline of Bash scripts like this prog1 | prog2 such that prog2 can see the exit code of prog1 and act differently based on that information. Is this possible?
4
votes
1answer
204 views

Changing a file's “Date Created” and “Last Modified” attributes to another file's

I'm using merge cap to create a merge pcap file from 15 files. For the merged file, I have changed the name to that of the first of the 15 files. But I would also like to change the merged file's ...
2
votes
0answers
36 views

gnome “switch user” shortcut or command line

Is it possible to switch user of gnome desktop environment by single command or any shortcut key, in centos 6.0, or Can we create shortcut key? I found "fusa", but still unable to install it.
1
vote
1answer
74 views

Pass bash script arguments in double quotes to php cli script

I am trying to pass arguments to a bash script and then to a php script, I have literally looked at 30+ links, and tried over a dozen examples, and I for whatever reason have not been able to get the ...
1
vote
1answer
93 views

syntax error in conditional expression while executing the shell script?

I am working on a project in which I need to make a url call to one of my server from the bash shell script.. http://hostname.domain.com:8080/beat After hitting the above url, I will be getting the ...
2
votes
0answers
42 views

Batch mv cronjob leaving some (not all) copies in source

I have a cronjob that runs every 5 minutes, looking for wavs and mp3s of the same name in a source directory and if it finds a corresponding pair, it moves both to a destination directory. The script ...
16
votes
2answers
398 views

How can a bash script detect if it is running in the background?

Is there way for a bash script to know if it is running in the foreground or background, and so it can behave slightly differently in each case?
4
votes
2answers
233 views

Command completion does not complete the files in the current directory

Something is wrong with my tab completion. Let's say I do this: cd test // works fine, go into test directory ls // works fine, displays all of the files Let's assume I have the following files: ...
15
votes
2answers
323 views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
2
votes
3answers
55 views

Tar compress folder without specifying the filename

Is it possible to use tar to compress a folder without giving the filename of the archive to store in? Normally you use: tar -zcvf prog-1-jan-2005.tar.gz /home/jerry/prog I want to do something ...
2
votes
2answers
105 views

Why does bash add single quotes to unquoted failed pathname expansions in a command before executing it?

I was exploring the tracing of commands using set -x (set +x to unset) in bash: Print a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and ...
-1
votes
1answer
42 views

Remove directory without `rm -r`

How to remove non-empty directory without using rm -r or find -delete ? I think it is related to unlink, perl or inode
2
votes
2answers
127 views

Allow NonRoot User to Mount a Particular NTFS External Hard Drive

I have a 4TB external hard drive connected to an Linux server. The fstab permissions on this drive are set so that only one particular non-root user has access to it: ...
4
votes
3answers
65 views

Why does export -p exclude $_ variable?

As far I know, there are 3 ways to see exported variables: $ export -p | wc -l 50 $ env | wc -l 51 $ printenv | wc -l 51 As you can see, export -p misses single variable. It's a $_ one: $ diff ...
6
votes
3answers
256 views

Remote ls on multiple machines

I want to connect to multiple machines specified in a file and perform 'ls' there. That's what I've come up with: for machine in $(cat machines) do echo "Connecting to " $machine ssh $machine ...
9
votes
2answers
844 views

Fastest way to concatenate files

I've got 10k+ files totaling over 20GB that I need to concatenate into one file. Is there a faster way than cat input_file* >> out ? The preferred way would be a bash command, Python is ...
2
votes
2answers
58 views

Running cron.daily in parallel

Being able to put a script in /etc/cron.daily is really nice because I can do it easily from a configuration management system or a package. However, my understanding is that all the entries in ...
3
votes
3answers
218 views

Transform a directory into file or a file into directory

I wanted to create a file named test. Accidentally I run mkdir test instead of touch test. Is it possible to convert test directory in a file named test? What about converting a file named test into ...
1
vote
2answers
63 views

Auto answering password for OPENSSL using HEREDOC [closed]

I have the following command but it doesn't work for me... cd /etc/postfix/ssl/ && openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024 <<PASS password password PASS The output ...
4
votes
2answers
353 views

Where is a shell script run from?

I have a shell script in /usr/bin. Let's call it hello. It contains this: echo "I am located in $PWD" echo "I am called from this directory: ???" Running hello from /home/Documents I expect the ...
3
votes
3answers
243 views

How can I extract/parse a complete URL from a semi random string?

I'd like to have bash parse/extract a full URL (and only the url) from a random short string. Examples: bob, the address is http://www.google.com or https://foo.com/category/example.html is up ...
6
votes
2answers
187 views

What's the most efficient way to grep for two completely separate things and assign the values to separate variables?

CentOS 6.x I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
2
votes
1answer
78 views

Converting bash script to fish

I'm trying to add the following bash scripts to fish, yet am having trouble getting the syntax in fish right. Here is the original script: export MINION_INSTALL=$HOME/minion export ...
3
votes
1answer
51 views

compgen warning: -C option not working as I expected

What is the correct way to use the compgen -C option? I'm trying to learn about Bash programmable completion, and in particular the compgen builtin function. I'm experimenting with the different ...
20
votes
2answers
529 views

How do I move all files output from a command?

I have this grep command to find files without the word Attachments in them. grep -L -- Attachments * I want to move all the files that are output from that command. How do I do that in bash? Do I ...
3
votes
1answer
133 views

adduser: Specify only one name in this mode

I'm trying to add a user with this command on my debian server: #!/bin/bash APPUSER="test1" APPGROUP="test2" # User adduser -c 'uwsgi user' --group $APPGROUP --system --no-create-home ...
2
votes
1answer
54 views

bash globstar matching

I have this directory structure: ~/tmp/globstar ɀ find dir -type f dir/file.ext dir/subdir1/file.ext dir/subdir2/file.ext and, with the globstar option enabled in Bash, I can say: ~/tmp/globstar ...
-2
votes
2answers
75 views

Input validation in a bash script [duplicate]

I've got the basics of bash scripting (I think anyways), and i'm trying to move on to more advanced stuff. I am trying to write a script that will perform input validation (the user must input either ...
4
votes
1answer
59 views

measure amount of data read from /dev/random

background I have written a collection of bash scripts (most of them in German only yet but if you are interested; download the archive not the single scripts) which help users create high-quality ...
2
votes
2answers
50 views

What is the bash syntax for extracting the values from multiple instances of the same argument?

I want to use multiple instances of command line paramater such as the -d option used by PHP for passing PHP options. I am currently using the getopts command in bash. With PHP invocation it would ...
1
vote
2answers
83 views

In bash script, how to capture stdout line by line

In a bash script, I would like to capture the standard output of a long command line by line, so that they can be analysed and reported while initial command is still running. This is the complicated ...
2
votes
2answers
87 views

Unicode text doesn't appeared correctly in shell

I'm using the terminal in Kali Linux and I try to type Arabic text the characters are shown but separated (appearance not correct) This what my shell shows me ex. لا ا ل ه ا لا ا ل ل ه, which should ...
1
vote
2answers
92 views

Why are bash tests so picky about whitespace?

As a primarily Java programer, I find the bash if-then construct quite confusing, especially regarding whitespace. Can anyone explain, why the first one works but not the second and third? #works if ...
1
vote
2answers
57 views

Fastest way to create a file of 1MM unique nanosecond timestamps

My current (slow) example is this: for i in {1..1000000}; do echo "$(date +%s)$(date +%N)"; done > 1m-example.txt Hopefully there's a better way. It's crazy slow.
1
vote
1answer
65 views

Getting 'no such file or directory' even though the file is clearly there [duplicate]

I'm having a perplexing issue. If I try to run a script via: root@myServer:~/dig# ./minerd.sh I get: -bash: ./minerd.sh: No such file or directory If I try: root@myServer:~/dig# ~/dig/minerd.sh ...
2
votes
2answers
49 views

Bash script to signal a concurrently running instance (same script) about a condition and increment counter

Background Here's what I want to achieve. I have a (potentially) long-running process. Now I have locking in place just fine and all is generally in order. However, since this is a scheduled job, ...
4
votes
2answers
125 views

How can I delete all unordered lines from a text file?

Overview Consider an ordered list interspersed with unordered elements, e.g.: Alligator Ant Falcon <-- Baboon Badger Armadillo <-- Caiman Cat How can this list be processed so that all ...
6
votes
1answer
188 views

What is the rationale for the bash shell not warning you of arithmetic overflow etc.?

There are limits set for the arithmetic evaluation capabilities of the bash shell. The manual is succinct about this aspect of shell arithmetic but states: Evaluation is done in fixed-width ...
1
vote
0answers
24 views

Why am I not receiving any system e-mails? [closed]

In my crontab, I have the following: * * * * * sh /home/rimmer/test.sh In /home/rimmer/test.sh I have the following: #!/bin/bash echo 'test'; I have also set chmod +x /home/rimmer/test.sh, of ...
2
votes
3answers
79 views

Installing crontab using bash script

I have created a script to install two scripts on to the crontab. #!/bin/bash sudo crontab -l > mycron #echo new cron into cron file echo "*/05 * * * * bash ...
2
votes
2answers
92 views

Command Line Photo Organiser Like Shotwell but to run on headless server

Does anyone know of a program (or even bash script) that can take photos from various folders and then consolidate them into one place and organise them into a directory structure by date in the way ...
3
votes
4answers
235 views

Execute a program at login

I'm running Arch-Linux ARM on a Raspberry Pi. My project goal is to have a barcode scanner attached to the Pi that forwards the scanned messages to a server in a LAN. To harden the system against ...
2
votes
1answer
33 views

Load application with module load and specify a different name from the default [closed]

I am using my local workstation to run applications stored on our local cluster. To load and run an application, I normally use: module load xxx However, there is a an application on my computer ...