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

0
votes
4answers
329 views

bash using a file name as input

Im pretty stupid when in comes to bash and I was hoping someone could help me. I would like to take the output of hg resolve -l which is in the format R somefile/filename U somefile/filename R ...
4
votes
3answers
587 views

Why do 'nohup' and 'disown' not work on SoX (invoked as 'play')

I can run this command: $ play mylist.m3u And music plays. I can then press Ctrl-Z to suspend the job, and issue bg to have it run in the background. However, if I then run disown and exit, the ...
4
votes
1answer
1k views

bash terminal [\t] (time) is not same timezone as 'date'

In my .bashrc file I configured how I would like my prompt to be displayed. My .bashrc is sourced in .bash_profile. The command in the .bashrc file is: PS1='[\t] \u@\h is $PWD :: ' I switched the ...
5
votes
3answers
2k views

How to generate new var names on the fly

I'm trying to generate dynamic var names in a shell script to process a set of files with distinct names in a loop as follows: SAMPLE1='1-first.with.custom.name' SAMPLE2='2-second.with.custom.name' ...
5
votes
2answers
2k views

Splitting bash command line argument

Is this the best way to split up a colon separated bash command line argument? #!/bin/bash hostlist=`echo $1| awk '{split($0,Ip,":")} END{for (var in Ip) print Ip[var];}'` for host in $hostlist do ...
3
votes
3answers
2k views

Create and Delete Amazon EC2 Volumes using a shell script

I am using this following script which does a regular backup of volumes on Amazon AWS cloud service. It creates new snapshots of the volumes and should remove snapshots older than two days. It is ...
6
votes
2answers
2k views

Can't understand this script. bash <<(curl -s http://xxx.com)

In a rails book, the author wrote the script to install ruby rvm. bash <<(curl -s https://rvm.beginrescueend.com/install/rvm) But I don't understand how it works. Could you explain this?
1
vote
4answers
2k views

Grepping over a huge file performance

I have FILE_A which has over 300K lines and FILE_B which has over 30M lines. I created a bash script that greps each line in FILE_A over in FILE_B and writes the result of the grep to a new file. ...
8
votes
1answer
5k views

Trap, ERR, and echoing the error line

I'm trying to create some error reporting using a Trap to call a function on all errors: Trap "_func" ERR Is it possible to get what line the ERR signal was sent from? The shell is bash. If I do ...
5
votes
5answers
2k views

Unix bash script check empty gz files [duplicate]

I'm trying to write a bash script that will go into a directory loop through the .gz files and delete them if they are empty (ie the uncompressed file contained within in empty. I've got a couple of ...
2
votes
4answers
317 views

Say I have a file's path, how do I reference that file's directory from the command line?

I can type: dirname ~/home/blah/file.zip for instance, and this works fine alone, but when I use this syntax as the parameter for some command it always reads 'dirname' as the desired directory. ...
17
votes
4answers
13k views

Command substitution: splitting on newline but not space

I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it. I have a file with contents ...
5
votes
3answers
2k views

Why `> my.log 2>&1 &` causes the job to sustain log out?

I use myscript > my.log 2>&1 & to run a script and collect it's output - so that when I logout - the script will still be running. It I were to start it with myscript & - it will ...
1
vote
1answer
439 views

How to 'ls' current directory (which is under svn) files info (path)?

How can I sort of list current directory contents (including sub-directories recursively) (which is under svn) files info (path relative to current dir)? I want this to get log in format like: ...
4
votes
4answers
8k views

How can I check if mysql is installed using a bash script?

I need to check if mysql is installed from within a bash script. What would be an efficient way of doing that? I thought I could do this: if [ ! -f `which mysql` ] ; then echo "foo" fi But I ...
1
vote
1answer
2k views

Connect to a remote mysql server with bash php or perl

What is the best and lowest resource way to connect to a remote mysql server (server1.example.com) and execute queries like INSERT into SERVICES (user, id) ($user, $id) from server2.example.com? ...
8
votes
3answers
6k views

Using in/out named pipes for a TCP connection

I've been fiddling with getting this to work for a while now, so I suspect some sort of fundamental misunderstanding about how pipes work is the root cause of my troubles. My goal is to initiate a ...
2
votes
2answers
127 views

Is there an easy way to stop and reissue a command?

I am doing Node.js development in Ubuntu and I'm curious if there is a way to quickly stop and restart a node server. I run this command to start my app: $ node app.js When I make changes to ...
6
votes
1answer
370 views

Emacs commands in xterm

I found that the commands I used to use in gnome-terminal, those I learned in Emacs, are only partially working in xterm. In some cases, I get strange chars like ÿ, æ, and â instead. Do you know how ...
14
votes
1answer
941 views

Why does variable expansion without $ work in expressions?

#!/bin/bash VALUE=10 if [[ VALUE -eq 10 ]] then echo "Yes" fi To my surprise, this outputs "Yes". I would have expected it to require [[ $VALUE -eq 10 ]]. I've scanned the CONDITIONAL ...
11
votes
4answers
5k views

su does not change user but does not respond with an error either

While logged in as root I would like to su to a specific regular user. I run su username and immediately receive the prompt back, still as root. There is no error given. I'm aware of the old "the user ...
76
votes
6answers
4k views

Run a command that is shadowed by an alias

Let's say i have the following alias in bash - alias ls='ls --color=auto' - and i want to call ordinary ls without options. Is the only way to do that is to unalias, do the command and then alias ...
1
vote
1answer
304 views

Switching source and destination (or undoing the mv, cp operation)

mv or cp commands both expect source and destination as arguments. In case you want to undo the change you made, or just change the source and destination you supplied before, what is the quickest ...
2
votes
2answers
291 views

How do I ad an if statement (regarding punctuation in a word) to this bash script

I have this bash script #!/bin/bash cat $@ | while read line do for word in $line do echo $word | circling-the-square # here's where i need to add the if statement: ...
31
votes
1answer
9k views

How to Navigate within bash's Reverse Search?

Bash offers the functionality to reverse search via Ctrl + R. Then one can type in a part of a command it will show a fitting entry from the history. Assume this is my history: vim foo1 vim foo2 # I ...
3
votes
1answer
2k views

bash: get last stdout [duplicate]

Possible Duplicate: How do I reuse the last output from the command line? If I for example type aptitude search dia I get a lot of unrelated stuff. At that point, I suspect that | head ...
1
vote
5answers
2k views

Start/stop program from website

I have some users on my machine that I allow to run small Mumble voice servers. I would like for them to be able to start/stop their voice server from a website (being ran by Apache). With the current ...
2
votes
2answers
300 views

Quick and dirty way to run a process more than once

I am looking for very simple bash script that would allow me to launch a process a few times. What's essential to me is that after the processes terminate, everything will clean up automatically. ...
3
votes
1answer
835 views

How to test the touch screen on embedded devices like iPhone / iPad / Kindle? [closed]

I want to test the touch panels on embedded devices like iPhone, iPad and Kindle against following criteria: Do a gesture, like tap, swipe, pinch ( zoom in/out) 10000 times and validate that every ...
2
votes
3answers
713 views

How can I turn ugly output into pretty, useful information?

How can I turn this ugly output into pretty, useful data? The output: /* ---------- TA#box#AbC_p ---------- */ insert_job: TA#box#AbC_p job_type: a #owner: bob permission: gx date_conditions: 1 ...
1
vote
2answers
498 views

sqlite3 bash grep username

#!/bin/bash username=$(sqlite3 db.sl3 "select user from main";) yad --list --column="#" "$username" --height 200 I want to display the usernames of my db in a list and then select one of theme. The ...
5
votes
2answers
17k views

How to check if a filesystem is mounted with a script

I am new at scripting ... I can do very basic stuff, but now I need a hand. I have a local filesystem that only will be mounted when I need to do a backup. I'm starting with this. #!/bin/bash ...
4
votes
4answers
10k views

Is there an online bash script testing site?

Sometimes I need to help friends with bash scripting. When I'm on a Windows machine, it's a working environment and I can't just setup Cygwin or use a VM. Is there some free scripting website I can ...
0
votes
2answers
10k views

Checking if files exist in some remote folders with bash

I need to do a script to look in some folders and send an email if there are files in these folders. I've tried to do something like this but I get errors with the command variable and print of the ...
0
votes
2answers
3k views

Why does this incrementing for loop return a bad variable?

I'm trying to call this shell script from within the CLI of GRASS GIS: for (( day=5; day<367; day+5 )); do # commands that I've tested without a loop. done exit 0 returns Syntax error: Bad ...
5
votes
1answer
2k views

“unexpected end of file” in bash script

I have this if in a bash script: if [ $ACTION = deploy ]; then ${JAVA_HOME}/bin/java ${JVM_ARGS} weblogic.WLST << EOJ connect('XXX','XXX','t3://XXX:8001') jndi(); ls(); ...
1
vote
1answer
185 views

cat command from textbook is not working on my Ubuntu Natty

I am trying to reproduce the following command from my textbook on my system, cat("2 3 4 5", "11 13 14 15", file="ex.dat", sep="\n") but I keep getting this error: bash: syntax error near ...
-4
votes
2answers
1k views

How to write bash script that deletes the oldest file in a directory if there are greater than N files in the directory?

Wondering how would one go about writing a script that: Counts the number of files in a directory. If that number is greater than a specified number N, delete the oldest file in the directory. For ...
7
votes
3answers
7k views

bash: /dev/stderr: Permission denied

After upgrading to a new release version, my bash scripts start spitting errors: bash: /dev/stderr: Permission denied in previous versions Bash would internally recognize those file names (which is ...
-5
votes
1answer
418 views

Linux: create list of text with multiple operators [closed]

I want to make a list like this: 7785237_770x770_de3b540dc13ed50023d17854513b40aa07e50a6a 732308_770x770_ec5c344c0114011a5306b31142ff9b001813f6d6 ...
4
votes
3answers
7k views

Why does bash variable expansion retain quotes?

> echo "hi" hi > VAR='echo "hi"' > $VAR "hi" Why is the output of the above commands different? A similar thing occurs with single quotes: > VAR="echo 'hi'" > $VAR > 'hi'
0
votes
2answers
418 views

Running a command based on output of previous command

Consider the following command. I want to echo "yes" if grep has output and echo "no" if grep returns no output. cat myfile | grep "something" Can I do this without if command?
3
votes
2answers
2k views

Passing a bash command-line argument containing a dot

How can a command-line argument containing a dot (.) be passed? Are there any escape sequences for capturing characters like dot? The following invocation of a bash-script from the shell does not ...
3
votes
2answers
823 views

pure shell complex substitution in variable

However it may be impossible, I hope I'm just bad man reader =) Is there any way to substitute text in variables on several patterns at time or even using back reference? For example, I have ...
13
votes
4answers
4k views

How can I find a rogue alias declaration?

I'm trying to find where a specific alias has been declared. I've searched all the usual places I know to look for aliases: ~/.bashrc ~/.bash_profile /etc/bashrc /etc/profile With no luck. I know ...
6
votes
3answers
1k views

Glob with Numerical Order

I have this list of pdf files in a directory: c0.pdf c12.pdf c15.pdf c18.pdf c20.pdf c4.pdf c7.pdf c10.pdf c13.pdf c16.pdf c19.pdf c2.pdf c5.pdf c8.pdf c11.pdf c14.pdf c17.pdf c1.pdf ...
5
votes
2answers
4k views

What causes ln: //: Is a directory?

When linking a directory to root, I get this error: $ ln -s ~/inbox/ / $ ln: //: Is a directory Bash autocompletes the directory path by adding a /. I've tried escaping without success. $ ln -s ...
3
votes
1answer
615 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
14
votes
3answers
6k views

Switching to `zsh`: Are all bash scripts compatible with `zsh`?

I'm looking to switch from bash to zsh but concerned about compatibility of bash scripts. Are all bash scripts/functions compatible with zsh? Therefore, if that is true is zsh just an enhancement to ...
20
votes
3answers
995 views

Where can I find documentation about the “sudo !!” command

I just learned that Linux has a sudo !! command which literally applies sudo to the last entered command. I had never heard about it. Is that a common control? Where can I find documentation about ...