Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
1answer
921 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
4answers
4k 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
117 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
995 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
4k 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
547 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
119 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
1k 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
1k 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
5k 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
9k 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. ...
3
votes
5answers
1k 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
53 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
65 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
413 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
129 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
133 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
131 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 ...
5
votes
3answers
5k 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?
3
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 ...
4
votes
2answers
7k 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
107 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
10k 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
818 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
2k 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
511 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
456 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
312 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
598 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 ...
5
votes
1answer
3k 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
870 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
799 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
221 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
597 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 ...
11
votes
3answers
6k 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
350 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 ...
0
votes
1answer
105 views

parameter extraction from multiple parameter output in bash?

Here's the bash script I am working on: i/p: ls *.py o/p: List of output files with .py extension 1.How do I know the number "n" of the .py files? 2.Then pump files one by one into the program to do ...
5
votes
4answers
3k views

What does <<< mean? [duplicate]

What does <<< mean? Here is an example: $ sed 's/a/b/g' <<< "aaa" bbb Is it something general that works with more Linux commands? It looks like it's feeding the sed program with ...
7
votes
3answers
8k views

How can I cd into a directory as root?

Let's say there's a directory that I don't have the privileges to access. Obviously sudo cd foo won't work, because cd is a shell builtin in every shell ever. So far, I've just been using sudo bash ...
1
vote
2answers
88 views

Associating variable with specific for loop file

I want to use for for a set of files. for file in fileA fileB fileC; do COMMAND $file $variable done For every $file I want to use specific $variable. (for example: fileA variableA; fileB ...
3
votes
2answers
4k views

using bash script to output new script: need mixture of variables to be replaced and not replaced

I'm having a problem with bash variable substitution. Here's a silly example of what I am trying to do. I need to output a new script from a bash script. A line (see echo in my example) has a mixture ...
2
votes
2answers
283 views

Is tty_nr referenced anywhere else in GNU/Linux procfs?

This is a problem I've been trying to solve on my own for some time without any luck. I'm trying to write a script that (amongst other things) can take an arbitrary PID and map it to TTY device's path ...
2
votes
1answer
2k views

Bash pipe output to more

I am wondering about some bash environment setting here: is it possible to set stdout of bash as a pipe to /bin/more? You know, like using vi as editor for your commands it should be possible to avoid ...
6
votes
3answers
109 views

How can I remove a file called “--help” with bash command line? [duplicate]

I've somehow managed to create a file with the name "--help". If I try to remove the file using "rm" funny stuff happens. Please help here's a printout of the dir listing: [pavel@localhost test]$ ls ...
1
vote
4answers
5k views

Zenity dialog windows have excessive height and cannot be resized. Bug workaround anyone?

I'm trying to do some things in zenity, and it's been driving me bonkers. To illustrate my problem, try running this: zenity --info --text "Hello there friends." Simple enough right. Now try this: ...
2
votes
2answers
4k views

How to find files by the time in their filename? [duplicate]

We have a directory contains files which contains time in their filename ./test.2013-06-11_06-01.gz ./test.2013-06-12_01-01.gz ./test.2013-06-13_03-01.gz ./test.2013-06-14_03-01.gz ...
7
votes
2answers
865 views

read -a array -d '\n' < foo, exit code 1

If I try to execute read -a fooArr -d '\n' < bar the exit code is 1 -- even though it accomplishes what I want it to; put each line of bar in an element of the array fooArr (using bash 4.2.37). ...
10
votes
4answers
32k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
14
votes
1answer
27k views

How to redirect stdout and stderr to a file and display stderr to console?

I know how to redirect to a file, and use tee; on a basic level. So $ alias outanderr='bash -c "echo stdout >&1; echo stderr >&2"' # A fake "application" displaying both output and ...
4
votes
3answers
1k views

Reading a binary file as an array of bytes or 16 or 32 bits using shell script

I am working on ARM-based modem Linux host machine and I need to read a bin file as an 8-,16- or 32- bits array. I basically need to encrypt the file in question and was thinking of just XOR-ing the ...