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
674 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
0
votes
2answers
456 views

remove a char string from a command output (sed, or maybe something else)

I'm trying to retrieve the distro name from the lsb_release -i output, but using lsb_release -i | sed 's/Distributor ID: //g' won't do the trick. What am I doing wrong? Or maybe should I change ...
2
votes
1answer
281 views

Simpler processing of shell script options

I'm looking for way to process shell script arguments that is cleaner and more "self documenting" than getopt/getopts. It would need to provide... Full support of long options with or without a ...
0
votes
1answer
106 views

Can't access server after rvm install

I messed up my server yesterday, and im not quite sure how to get it straight again. After trying to install SiriProxy by severall guides failing one after the other on the step for rvm and ...
2
votes
1answer
201 views

Why is it possible to refer to a closed stderr under bash?

I'd like to know why bash doesn't display an error message when we refer to a closed stderr. When it comes to other file descriptors, they have to be opened if we want to, for example, duplicate them. ...
2
votes
1answer
124 views

Stderr of piped shell scripts isn't always displayed

I piped my own shell scripts for some testing and accidentally noticed something strange. Namely, the stderr of those piped processes isn't always displayed on the screen. I simplified the scripts ...
2
votes
3answers
221 views

Read ~/.bash_profile but not /etc/profile

I noticed that you can prevent reading /etc/profile by running bash --noprofile However this also stops ~/.bash_profile from being read. Can Bash be invoked in such a way as to read ~/.bash_profile ...
1
vote
1answer
129 views

How to more easily specify tasks for batch, using command prefix tool?

The tool batch that comes with the atd daemon is pretty useful in principle, running commands only when the system utilisation falls below a certain level (by default, 1.5). However, using it (and ...
13
votes
1answer
12k views

Delete last N lines from bash history

When accidentally pasting a file into the shell it puts a ton of ugly nonsense entries in the bah history. Is there a clean way to remove those entries? Obviously I could close the shell and edit the ...
2
votes
1answer
386 views

bash scripting add arguments

I have created a script which takes parameters and arguments. I want to insert the --help argument. I already know how to parse normal arguments with -, but I don't know how to parse the -- ones. to ...
1
vote
2answers
1k views

OS X setting environment variables

I have OSX 10.8.2 with ZSH as my shell and iTerm as a terminal (don't know if the last thing is relevant). I have to mention that I'm relatively new to OSX. I'm trying to set up some environment ...
12
votes
3answers
1k views

Practical use for moving file descriptors

According to the bash man page: The redirection operator [n]<&digit- moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is ...
6
votes
4answers
3k views

What's the difference between a hard links and copied files?

RHEL 6 My understanding is that hard links include a copy of the original file and that I could delete a hard-linked file in one directory, and it would still exist in the other directory. If ...
3
votes
1answer
324 views

Significance of arrows symbols in duplicating/closing file descriptors under bash

I'm reading a book about Linux command line where author doesn't seem to follow the conventions in bash manual regarding arrows symbols used in redirection operations. Namely, he always uses left ...
1
vote
4answers
247 views

Why would someone want to change the last access date of a file without making actual changes within the file itself?

CentOS 6 I'm studying RHEL / Centos and recently learned that the touch command can be used to change the last access date of a file. I'm struggling to understand a practical reason why anyone would ...
2
votes
1answer
2k views

How to run Steam from the Xfce desktop?

I've installed Steam on Debian 7.0 without any hassle, and I can run it by typing steam &. I've set it as a desktop launcher in Xfce, but when I ran it, nothing happened. Then I've check the ...
3
votes
3answers
63 views

How to separate numerical values from identifiers

I'm currently writing a shell script that seperate values from their identifiers (retrieved from grep). For example, if I grep a certain file I will retrieve the following information: value1 = 1 ...
5
votes
1answer
428 views

In bash, can I asynchronously open sockets and use them later?

I had no idea that Bash supported so many advanced features! I started working on a simple network program to try and use some of these things I found. My particular program is a basic redis client ...
2
votes
1answer
3k views

Bash vs ksh pipes

I am stuck with some problems with my scripts in ksh. FWIW the problem which I am unable to overcome is that when I use a structure such as this command | while read VAR1 do many.commands using ...
2
votes
2answers
295 views

How to send text to a command and THEN read from terminal

I'd like to know if it's possible to send some to a command's stdin and then keep reading from the terminal. The problem i'm trying to solve is executing some initialization code every time i open a ...
1
vote
1answer
623 views

Sending Emails from bash script in Solaris VM

I am trying to send emails using the following bash script: /bin/mail -s "#subject" "$emailto" < "$message" It works fine on my local machine but does not work on my VM. I looked it up and read ...
10
votes
4answers
6k views

combine output from two commands in bash

Is it possible to combine output from these two commands? node ~/projects/trunk/index.js python ~/projects/trunk/run.py run Neither command exits so I'm not sure how to do this.
1
vote
2answers
2k views

bash script that uses nc for telnet reports “: command not found OK”

If I go to a bash prompt and run the following command (to flush memcached): echo "flush_all" | /usr/bin/nc 172.16.198.130 11211 it works and returns "OK". If I put that same command in a one-line ...
1
vote
2answers
762 views

Ignore all matches to negated extglob pattern in recursive ls

I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash). The only way I can think of to do this using ls is to shopt -s extglob ...
0
votes
2answers
147 views

A problem with $RANDOM range in bash

why the code below, supposed to display a random from 2-3 range, actually works as if the range was 2-4? echo $((RANDOM%3+2))
6
votes
3answers
5k views

whiptail or dialog

I am going to create script which will use user input, so I decided to use whiptail, but little bit confuse that which one is portable and will work in ubuntu 10.x and higher and CentOs5.x and higher. ...
1
vote
1answer
102 views

what is diffrence between “$var” and “${var}” [duplicate]

i have seen in many script usage of "$var" and "${var}", so I just want to know diffrence between "$var" and "${var}"
2
votes
3answers
877 views

How to stop `grep` from truncating pipe output

Is there any way to have an echo at the end of a pipe simply append to the current output rather than removing it all? For example, how can I keep the output for my cat and grep and add "END OF ...
1
vote
1answer
375 views

Why does printf ignore the IFS when printing out the result of my script?

This is a follow up to a question posted on SO. I've written a script called except which should print all filenames / directories except the ones given like so. $ ls a b c d $ rm $(except b d) $ ls ...
1
vote
3answers
792 views

Shell script Variable Structure

How can I create a variable with a file name format like : FileName pattern: SnapshotIR__somenumber.csv I tried something like : TODAY=$(date +"%m%d%Y") SNAPSHOT = $(SnapshotIR$TODAY*.csv) I ...
5
votes
3answers
2k views

Create symbolic links to files using wildcards

I want to create symlinks to multiple files: ln -s dev-*.php 's/dev-(.*\.php)/$1/' Results hoped for: site.php links to dev-site.php file.php links to dev-file.php What's the most ...
3
votes
1answer
185 views

Bash 3.0 not supporting lists?

I have written a small script that add particular IP addresses taken from a config file and then puts it in a list : WAS_IP=$(grep "<was_ip>" $CONFIG| cut -d '>' -f 2 | cut -d '<' -f 1 ...
3
votes
1answer
692 views

how to start from within my shell-script xterm which starts mplayer and plays the files that are the argument of the script

What I want to do: Start my script with a list of files as arguments. From within my script I want to start xterm that starts mplayer with these files. I tried several things. I call my script like ...
6
votes
2answers
8k views

Difference between >> and >\> operators?

RHEL 6 Is there a difference between the >> and >\> operators? I read the following blurb in a RHEL training book: "You can add standard output to the end of an existing file with a ...
3
votes
1answer
679 views

Change Xfce Theme from bash script

I have a convertible notebook, and am writing a bash script to change from standard desktop to tablet mode. I am running XFCE. Currently, the script is switching reading the orientation from a ...
4
votes
2answers
5k views

Iterate over multiple parameters with spaces in bash script

I have a bash script for my RaspberryPi (running Raspbian) that is supposed to take multiple file names as parameter(s) and play one after the other (using omxplayer). The basic structure is this: ...
4
votes
1answer
822 views

Is there a way to temporarily change the terminal colour?

I use the gnome-terminal and most of my editors with a white on black theme as I find its easier on the eyes. One of my labs requires screenshots of the terminal (with the process) to be submitted ...
20
votes
2answers
20k views

What do the scripts in /etc/profile.d do?

I am reading about basic shell scripting from Linux Command Line and Shell Scripting Bible. It says that the /etc/profile file sets the environment variables at startup of the Bash shell. The ...
1
vote
1answer
98 views

Pipe each last run command to a script

I want to use realiser to know if I should have used an alias each time I run a command in my bash terminal. The README gives the following example for ZSH: function last_command() { echo `history ...
3
votes
1answer
73 views

How to put an argument vector with an argument containing spaces in a bash variable

How can I store an argument vector with an argument containing spaces in a bash variable? For example, I want 2.sh to print b c 1.sh #!/bin/bash ARGV='a "b c"' ./2.sh $ARGV 2.sh #!/bin/bash ...
5
votes
1answer
6k views

how to compare two xml files having same data in different lines?

I have two files have same data but in different lines. File 1: <Identities> <Identity> <Id>048206031415072010Comcast.USR8JR</Id> ...
0
votes
2answers
157 views

regex, only the first occurence

I have a pipelined output from free -o -m | awk '{print $4}' I want take step by step two numbers the first and the second line. So i need two regexes. I tried with ^[0-9]{1,3}$ but this match all ...
4
votes
3answers
804 views

How to attach gnu screen without knowing tty number

After starting multiple gnu screen sessions with screen -S name1 screen -S name2 I would like to selectively attach to them. If I do screen -D -R name1 it will not attach but instead print: ...
6
votes
3answers
876 views

Tar piped to split piped to scp

So I'm trying to transfer a bunch of files via SCP. Some of these are too large to be stored on the recipient (Android phone, 4GB file size limit). The sender is almost out of space, so I can't ...
2
votes
4answers
1k views

How to write a very simple wrapper that provides default parameters?

Given a program that requires some parameters, e.g. program -in file.in -out file.out, what would be the simple-most approach to write a bash script that could be called with or without any of these ...
2
votes
3answers
1k views

Query list of servers for memory/cpu allocated

Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format: HOSTNAME1 CPUS: 12 ...
0
votes
3answers
3k views

Move all files to a new directory excluding that directory [duplicate]

I have the following: ~@matrix:~/btp200/assignments> ls -la total 40 drwxr-xr-x 3 molszewski1 users 4096 Feb 6 13:20 . drwxr-xr-x 6 molszewski1 users 4096 Feb 6 13:14 .. -rw-r--r-- 1 ...
16
votes
3answers
7k views

Pseudo files for temporary data

I often want to feed relatively short string data (could be several lines though) to commandline programs which accept only input from files (e.g. wdiff) in a repeated fashion. Sure I can create one ...
1
vote
1answer
461 views

bash autocomplete not working, does not 'complete'

I my bashrc. I have a bash completion for the command scp implemented as follows function _scp_complete { COMPREPLY="" COMPREPLY+=( $(cat ~/.ssh_complete ) ) COMPREPLY+=( $( find . ! -name . ...
3
votes
1answer
448 views

Why do new terminals in Awesome spawn with SHLVL>1?

I have a PS1 which shows the SHLVL if it's not 1 to quickly see if I'm in a subshell. This works as expected when using GNOME, but when I spawn a new terminal in Awesome WM (Mod4+Return) it always ...