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
2answers
1k views

How can I make “bind” command to work in sh shell

How can I make the next script to run when I'm using sh shell: #!/bin/bash bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward bind '^[[1'=prefix-2 bind '^[[1~'=beginning-of-line bind ...
3
votes
2answers
799 views

Bad substitution inside xargs subshell?

I'm using this command to process PNG files: find . -iname "*png" -print0 | xargs -r0 --max-procs=4 -n1 sh -c 'pngnq -s1 $1 && advpng -z -4 -q ${$1%.*}-nq8.png' - It seems to actually work ...
3
votes
1answer
3k views

Executable symbolic link file not working

On Mac OSX, I am having trouble with a pretty simple thing. My symbolic link doesn't want to execute. Can you help me spot the trouble? Thanks! $ echo $PATH ...
0
votes
2answers
870 views

Redirect all stderr of a console and subsequent commands to a file [duplicate]

I know how to redirect stderr to a file or to the stdout when I issue a command: command 2 > log or command 2 > &1 or even command 2 > &1 > /dev/null. However, I want to redirect ...
1
vote
1answer
340 views

difference between bash, -bash and /bin/bash in ps output [duplicate]

Someone had spawned a while true loop in bash (logged in as root) on a server. It kept spawning processes, which fortunately exited but I needed to kill the parent. I came to know it was spawned ...
7
votes
1answer
156 views

The shell's “delete word” shortcut deletes too many characters

Under Bash some behavior of Alt+d has been driving me crazy since years and I figured out that maybe it could be fixed with a setting. If I'm at a terminal and issue a command like this: ...$ cat ...
5
votes
1answer
647 views

command substitution handling in fish vs. other shells (sh, bash, zsh)

The program mc (Midnight Commander) is not intended to be used for command substitution, but I would like to know why different shells behave differently when this program (and it seems like other ...
1
vote
1answer
144 views

Where is the Ctrl+/ (^/) bash shortcut for undo defined?

I can not find the mapping in bind -p nor in stty -a. Also, it only works in the terminal emulators I've tried (xterm, konsole, gnome-terminal) and not in the linux system console. I think it's ...
12
votes
8answers
4k views

How to remove multiple newlines at EOF?

I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected ...
1
vote
1answer
383 views

Building Virtualbox Linux Headers

I am trying to get Virtualbox running on my Acer C7 with Ubuntu 13.04. I ran the script posted here but I am getting the following error after this point in the script. # make-kpkg kernel_image ...
1
vote
2answers
1k views

Mysterious bash instances using a lot of CPU, how can I debug?

I seem to have multiple bash processes running that are taking up most of my CPU. This is the output of top -c: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 20116 ...
0
votes
1answer
33 views

Read files in Directory and take diff

I have two directories named comp1 and comp2 and both have files named file1 and file2. I need a bash script which read file1 from both the directories and take diff of each file and redirect to some ...
1
vote
3answers
1k views

Renaming or making filenames unique

I have written a plsql procedure using utl file to create files in the temp directory in Unix. I am sending the names of the files to a shell script to mail these files and delete after mailing from ...
17
votes
3answers
1k views

Run commands at random

I want to run one of the two commands C1 and C2 at random. How do I do that on commandline (bash)? Will appreciate if a one-liner is possible.
1
vote
1answer
59 views

How and where can I permanently set $ program file to have extra argument '&'

When I run a program from terminal like so: $ program file For example $ gedit myfile.txt I cannot think of a time when I would not prefer to use '&' so that I can free up my terminal ...
0
votes
2answers
683 views

Assigning a value with echo piped together with the bc command and using a variable as an argument

Basically i'd like to assign to variable $finalbyte a value (which consists of a binary representation of a byte e.g 11100000). So trying to do that i put the following as part of some script: ...
1
vote
4answers
1k views

how to replace a value with a calculation in bash/sed

I used bash sed to replace ip address in a group of files, i.e 10.1.1.x => 10.2.2.x-19: file1: 10.1.1.29 => 10.2.2.10, file2: 10.1.1.30 => 10.2.2.11, file3: 10.1.1.31 => 10.2.2.12, ...
0
votes
2answers
542 views

sed - replace complex lines in a file using variables

How do I replace a complex line in a file using sed? For example I want replace a udev rule in /etc/udev/rules.d/70-persistent-net.rules. This doesn't work: OLD_RULE='SUBSYSTEM=="net", ...
0
votes
1answer
1k views

Expression error in bash script

I am getting this really weird error despite of the fact that the same script runs fine on one platform (Arch linux) but not on my other mobile platform (Maemo Linux). I'll pass here the relevant part ...
9
votes
3answers
2k views

Trapping errors in command substitution using “-o errtrace” (ie set -E)

According to this ref manual: -E (also -o errtrace) If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR ...
1
vote
1answer
730 views

Bash command that uses wildcard in place of folder to copy folder contents of multiple files into one directory?

I have a directory ~/dir that contains a bunch of random folders like: ~/dir/av 801 and ~/dir/lm 320. I want to copy the contents of every inner folder (ie: av 801) into a different directory. The ...
1
vote
3answers
3k views

Trouble with read line script in Cygwin

I'm on windows 7 using Cygwin. My script and text file are located in the same directory. #!/bin/bash while read name; do echo "Name read from file - $name" done < /home/Matt/servers.txt I get ...
0
votes
1answer
85 views

Resume input from user after file is read [duplicate]

I have a program that reads user input—moves, it's a boardgame—from the user. Like so: $ game enter your move: # etcetera The first N moves I need to repeat each time, so I put them in a text ...
1
vote
3answers
761 views

How to capture the standard output of a script that depends on the user for some input?

There is a script that requires me to enter the password before it continues: bash-3.2$ ./script.sh <parameter_list> Enter the password for the Database: .. .. I am interested in capturing ...
5
votes
3answers
3k views

limiting size of logfile from a variable

How can I limit the size of a log file, which is saved in the form of 'foo.txt', from within a bash script please? I want to put in the variables 'LOGFILE=50 mb' and it uses that size, or whatever ...
0
votes
2answers
419 views

I need to check a list of directories if it contains a directory newer than 1 month before now

Maybe the title is quite confusing so i'll try to explain what i have done until now. First of all i have build the list of directories i want to investigate with the code below: ...
1
vote
1answer
105 views

Why should I use $[ EXPR ] instead of $(( EXPR ))?

On the paragraph explaining arithmetic expansion, Bash's user guide uncovers 2 different ways of evaluating an expression, the first one uses $(( EXPRESSION )) and the second one uses $[ EXPRESSION ]. ...
4
votes
2answers
747 views

Passing a code block as an anon. function

Is it possible to treat a block of commands as an anonymous function? function wrap_this { run_something # Decide to run block or maybe not. run_something else } wrap_this { do_something ...
1
vote
1answer
875 views

Resume bash session in new TMUX or SCREEN? [duplicate]

Sometimes I'll start doing something fast. I've got something to do, and I need to get it done now. Then of course i realize that I need to do something else to help me finish what I started, so I ...
5
votes
2answers
4k views

Graphically ask for password in a bash script and retain default sudo timeout setting

The sudo -A (SUDO_ASKPASS) option apparently causes sudo to lose the timeout (e.g., timestamp_timeout) setting. I want to use the sudo -A option but I want to retain the default timeout (e.g., 15 ...
3
votes
2answers
6k views

Find the process id of a java application in a bash script (to see if the target application is already running)

I know there are a million questions on getting the process ID, but this one seems to be unique. Google has not given me the answer, so I hope stackexhange will help rather than close this question. ...
1
vote
3answers
781 views

Prevent text/screen blinking when doing clear

My script doing something like: while :; clear do_a_lot_of_output_here sleep 1 done Is it any options to prevent screen of blinking when I'm doing clear and output? I want to do it like ...
2
votes
1answer
52 views

Why is MAIL unset in graphical environments?

I get new-mail notifications when running bash interactively on Linux console but I don't get them on xterm or konsole. The environment variable MAIL is set to /var/mail/USER upon logging in on the ...
0
votes
1answer
59 views

Test for files containing certain numbers on its names

Suppose that the folder $folder contains the files 2012-01,...,2012-N1,2013-01,...,2013-N2 and so on. I'd like my script to ask for a natural number M and: if the files 20M-* exist then ask for ...
0
votes
3answers
326 views

Change terminal prompt Ubuntu

I have cloned a git repository to a folder in my workspace: /home/jose/workspace/very-very-very-long-repository-name/ so when i browse to it in my terminal it looks like ...
1
vote
3answers
121 views

I need to turn a series of commands piped together into an alias in .bashrc

sudo ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' The above command when run from terminal outputs the right "internal" ip address. When I try to pass as alias like: alias ...
3
votes
3answers
110 views

Is it safe to assume that null or unset variables will be substituted with zero in bash arithmetic expressions?

I found the following statement in the bash manpage (version 4.2) under the Arithmetic Evaluation section. A shell variable that is null or unset evaluates to 0 when referenced by name without ...
1
vote
1answer
110 views

bzr get last commit message using bash

I am using bash to try and get the last commit message of the most recent revision on a tree. In the documentation the closest thing I found was: bzr log -l 1 --line Which outputs: 45: Firstname ...
4
votes
3answers
3k views

How to stop redirection in bash

I use : exec >script.log 2>&1 in my script to redirect all output to a file. At the end of the script I would like to print a message to the screen. How do I stop the redirection?
4
votes
1answer
1k views

how to make my bash script look 100% like a GUI app (so user never sees terminal)

I created a bash script using kdialog (and it runs on Kubuntu 12.04). The GUI is used for every user interaction (after the first one). However, the script still has to be launched from the terminal ...
3
votes
2answers
3k views

How do I run a command on multiple files

This is pretty basic, I have a folder with several subfolders of JS files and i want to run Google's Clojure compiler on all of the files in those folders. The command to process a single file is as ...
2
votes
1answer
94 views

'echo' eats part of the message

I want to write a script that will dump all partitions of my android device through the android debug bridge and since this is a time intensive process I want to notify the user about the progress by ...
6
votes
1answer
5k views

How to input / start a new line in bash terminal?

I notice some sample bash for loops are spread out over multiple lines in examples for VARIABLE in file1 file2 file3 do command1 on $VARIABLE command2 commandN done (eg here ...
2
votes
2answers
624 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
3
votes
2answers
1k views

Cron jobs and mail notification

I have (from one tutorial) cron job which make weekly backup on my website and is working fine. #!/bin/bash NOW=$(date +"%Y-%m-%d-%H%M") FILE="mysite.com.$NOW.tar" BACKUP_DIR="/home/user/backups/" ...
0
votes
2answers
395 views

How to interact with program from command line

Is there any method to interact with a program directly from the commmand line? For example, I've a program, data.o, which produces a file mydata.out and then I want to plot it with gnuplot. I can ...
0
votes
4answers
347 views

Use grep with or [duplicate]

How do I search in a textfile with grep for the occurrence of a word or another word? I want to filter the apache log file for all lines including "bot" or "spider" cat ...
3
votes
3answers
261 views

Dmenu Processes Forked by Bash?

I was looking at the output of pstree, and realised that processes that I started using dmenu seem to fork from bash. What is the reasoning behind this? And is there any way I can make dmenu behave ...
3
votes
2answers
337 views

Refer to an item in `dirs`

I use pushd to work with multiple directories in bash and zsh. I've aliased dirs to dirs -v so that I get an ordered list when I want to see what's on the directory stack: chb$ dirs 0 ...
4
votes
1answer
2k views

Use the terminal's autocomplete path feature for input to a shell script

I want to make a script that: (1) Gets a path giving the user the ability to use tab to autocomplete, then (2) gets a filename from the user, and then (3) creates a file at that path with extension ...