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

5
votes
1answer
660 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
154 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
402 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
728 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
552 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
740 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
90 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
790 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 ...
6
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
445 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
781 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
918 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 ...
4
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
851 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
60 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
340 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
125 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
111 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
113 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
4k 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
95 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
6k 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
643 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
416 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
380 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
265 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
366 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 ...
3
votes
2answers
536 views

Running up to X commands in parallel

I'm running something like this: find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do echo "Encrypting $file..." gpg --trust-model always --recipient "me@myself.com" ...
4
votes
1answer
554 views

bash: Accessing function call stack in trap function

Working on a bash function call stack trace... Script traps errors and runs a callStack() function. But on trapping, It always shows a call stack for the callStack() function itself instead of the ...
2
votes
1answer
185 views

Is it alright to have two PATH variables in .bash_profile

I am trying to setup Metasploit on osx 10.7, but I need to edit my .bash_profile and I noticed something unusual to me. I have been reading about setting the environment variable on ...
3
votes
2answers
463 views

convert bulk of text files to pdf with naming based upon header file

Knowing that "How to convert from text to .pdf" is already well answered here link and here link, I am looking for something more specific: Using Claws-Mail [website] and a Plug-In [RSSyl] to read ...
10
votes
3answers
4k views

cat all lines from file, which are after “KEYWORD” [duplicate]

I have a file, with a "KEYWORD" on line number n. How can I print all lines starting from line n+1 until the end? For example, here I would liek to pro=int only lines DDD and EEE AAA BBB CCC KEYWORD ...
0
votes
1answer
257 views

What to do when result from pipe is not last argument in next command

The example below shows what I want to do, namely take the result from my last pipe and put it into the middle of the next command (where I wrote $RESULT_FROM_FIND_COMMAND). $ find . -name ...