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

8
votes
6answers
8k views

Shell script for moving oldest files?

How do I write a script for moving just the 20 oldest files from one folder to another? Is there a way to grab the oldest files in a folder?
25
votes
2answers
1k views

What does a “< <(…)” redirection mean?

I've seen that rvm (ruby version manager) is installed using the following command: bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) So as I ...
55
votes
16answers
41k views

How can I get my external IP address in bash?

I need to find my external IP address from a bash script. At the moment I use this function: myip () { lwp-request -o text checkip.dyndns.org | awk '{ print $NF }' } But it depends on ...
3
votes
1answer
3k views

Split video file into pieces with ffmpeg

When you want to extract two minutes of a video file from minute 2 to minute 4, you will use command ffmpeg -i input.mpg -sameq -ss 00:02:00 -t 00:02:00 output.mpg I'd like to split the video into ...
0
votes
1answer
456 views

Variable assignment in .bash_profile has no effect

I added the following to my .bash_profile: JAVA_HOME=$JAVA_HOME:/usr/java/jdk1.7.0 export JAVA_HOME However, when I echo $JAVA_HOME it outputs an empty string. Why weren't my changes to ...
21
votes
4answers
3k views

Change cursor shape (or color) to indicate vi mode in bash

To clarify: I am not asking how to change the cursor when using vim within a terminal. I want the cursor to change when switching between input and command mode within Bash's vi-mode: set -o vi ...
10
votes
1answer
943 views

What is a good example of a bash script to study in order to learn good coding conventions?

I've learnt the basics of programming in bash. I'd like to study a few examples of bash scripts so that I can learn good habits for bash scripting. In particular, I'm interested in examples of bash ...
3
votes
4answers
1k views

Detach a daemon using sudo?

I noticed that sudo continues to run after executing any of the following lines. Is there any way to detach the daemon completely so sudo does not continue running? sudo -u user daemon & sudo -u ...
7
votes
1answer
5k views

How to fix character encoding in bash (arch linux)

I have some issues with the encoding of german umlauts in bash. It mostly is working fine, but when i am typing a invalid command, the error message generated by bash contains strange escape sequences ...
2
votes
2answers
249 views

List files that occur lexically after/greater than a given prefix (or, run database upgrade scripts in a proper order)

I'm trying to create a shell script that runs through a bunch of SQL scripts. I've these files: $ ls upgrade/ 01-foo.sql 02-bar.sql 02-baz.sql 03-foo1.sql 04-buz.sql And I've got the version of ...
15
votes
1answer
513 views

How do ${0##*/} and ${0%/*} work?

I'm quite confused about the following regular expressions I found in a shell script: ${0##*/} ${0%/*} How do they work?
2
votes
2answers
126 views

How can I create a terminal window with one tab per long-running script that I can individually kill with ctrl-C and restart?

I am working on an application that requires running many long running scripts, some of which I want to restart from time to time. Currently, I am trying to use gnome-terminal to solve this problem, ...
2
votes
3answers
608 views

export script function

I am trying to implement the solution found here. However, a coworker suggested that instead of adding functions directly to a .bash_profile or .bashrc file that instead, the custom scripts be put in ...
2
votes
2answers
762 views

Bash: How do you view text that has been “scrolled up too far” in the terminal?

I know there is a simple unix command that allows you to view things from the top and/or allows you to scroll indefinitely toward the top. Not sure what to call it, so it's difficult to google. Thanks ...
4
votes
4answers
1k views

Error with if [ -n $diffCurr ]: Too many arguments

I have been using the below code ok for sometime, but now, I get an error java Editor < "input/editor$i.in" > "tmp/editor$i.out" diffCurr="$(diff "tmp/editor$i.out" "output/editor$i.out")" if [ ...
5
votes
2answers
3k views

Spaces as line breaks from inline for loop command

Someone care to enlighten me as to why the spaces in the first command seem to be interpreted as line breaks? Also occurs substituting print for echo. $for l in $( find *.txt -exec head -1 {} \; ); ...
9
votes
3answers
7k views

touch all folders in a directory

I am trying to update the timestamps of all folders in the cwd using this: for file in `ls`; do touch $file; done But it doesn't seem to work. Any ideas why?
1
vote
3answers
4k views

Rename Multiple files and add date before the files

I have a folder contains one or more tar.gz files. I want to add current date before each files when the script run. For example: Two file name(those files will be created each day, but the name ...
1
vote
0answers
102 views

Why does cd // work? [duplicate]

Possible Duplicate: unix, difference between path starting with '/' and '//' On my Mac OS X Lion box, with Bash: $ cd // $ pwd // $ ls Applications System cores ...
2
votes
1answer
1k views

Convert pdf to jpg keeping the same name; resize & create thumbs then rename?

I have a lot of pdf files (3308) on which I must apply four steps: 1) I have to convert all to jpg I found this little script on the web with ImageMagick: batch converting pdf to jpg I want to do ...
3
votes
2answers
1k views

Bash prompt keeps disappearing

I have a weird issue where my Bash prompt often completely disappears on a backspace. Doesn't make any sense to me, but it happens often: I can't really think of why this is happening. Am I ...
1
vote
3answers
432 views

Evalute passed in variable in bash

Is there a way to pass in a variable as an argument to a bash script and have it evaluated scoped by the bash script? Given: # cat /path/to/file/of/host/names bob tom joe etc... # dofor FILE=$1 ...
2
votes
2answers
493 views

How to execute script on logging out?

I'm reading The Unix Programming Environment. There is an exercise question to print how much CPU time you have consumed when you log off by editing .profile. I tried with this trap 'times' 0 1 2 15 ...
1
vote
1answer
465 views

Finding duplicate files

I need to write a bash script that finds duplicate files, but in addition to md5sum it needs to use cmp to do the final check. I tried the command below in my shell. How can I add a loop and put it ...
2
votes
1answer
6k views

send html using mailx

I'd like to send a html file from a host using mailx but instead of interpreting it as html it would send it out as text (html codes). Is there a way to send it as html? (cat <<EOCAT Subject: ...
7
votes
2answers
3k views

Distinguishing a regular file from a symlink

I'm writing a bash script that needs to distinguish a regular file from a symlink. I thought I could do this with if/test expression, but it doesn't work as I expected to: $ touch regular_file $ test ...
1
vote
2answers
1k views

How to group grep results?

I have a file that contains results grouped into categories. For example: checking results for $var here are some results1 for $var status ok here are some results2 for $var status ok here are some ...
8
votes
9answers
5k views

linux diff tools: create list of modified files

How do I create a list of modified files programmatically using linux command line tools? I'm not interested in the difference in any particular file (delta, patch). I just want to have a list of new ...
5
votes
4answers
1k views

Last failed command in bash

The $? variable holds the exit status of last run command. Is there a variable that holds last run command itself?
6
votes
4answers
410 views

Bash: test whether original script was run with `-x`

Is it possible to test whether a bash script was executed with -x? I'm writing a script which also runs some remote scripts, and I'd like to be able to do something like: USE_X="$( run_with_x ...
3
votes
2answers
3k views

Ignore escape characters when printing string in shell script

I just wrote a simple shell script to save a LaTeX expression as a PNG file. It works fine, except for the LaTeX-syntax for "next row", i.e. the double backslash \\. When for instance my input ...
2
votes
2answers
308 views

perl regex replacing globally when global not selected

I'm using Ubuntu 11.04 and wrote a small script that searches within text files for certain "tokens" and replaces with some a prewritten snippet from a template file of the same name. The text files ...
13
votes
3answers
2k views

How to delete part of a path in an interactive shell?

Is there a shortcut in bash and zsh to delete one component of a path? For example, if I type ls ~/local/color/, and the cursor is at the end of line, is there a shortcut to delete the color/ at the ...
1
vote
1answer
344 views

root shell isn't using --color=auto

Does anyone know why the root user doesn't have a colour coded shell? It would seem to me the one person who navigates the file system the most is the root user, s/he would benefit most from the ...
1
vote
1answer
491 views

Why does curl fail while using this export?

I'm doing some stuff with Facebooks FQL at the moment, and I'm using curl on the command line to test some of the responses of it. I'm also using export to keep the params seperated for easy editing. ...
9
votes
2answers
2k views

Piping for loop output prevents local variable modification

I'm trying to write a simple bash function that takes, as its arguments, a number of files and/or directories. It should: Fully qualify the filenames. Sort them. Remove duplicates. Print all that ...
6
votes
1answer
5k views

Running a bash script from a zsh shell

I'm having problems running a bash script on zsh. The script is similar to the one below and is supposed to run under bash: #!/bin/bash echo "<235234>" | egrep -oe [0-9]+ However, my shell ...
0
votes
1answer
150 views

how will I make interactive login

I'm having trouble in making script with interactive login. I have made one but it doesn't ask the login, it automatically log in when i run the script. i just need the output like this: please ...
4
votes
2answers
266 views

Understanding quotes in a bash conditional instruction

My friend is messing around with Bash scripts and he wanted me to take a look at them (he had another friend do it for him). One of the commands is if [ "`pidof transmmission-gtk`"=0 ]; what ...
2
votes
2answers
839 views

How do I install multiple java command-line programs?

I have a bunch of java command-line programs I've written and would like to install for all users. Building with NetBeans, I get a /dist directory which contains myprog1.jar and a /libs directory ...
9
votes
1answer
706 views

How do you omit “./” when running scripts on current directory

On some tutorials over the internet they can run a script on the current directory without doing: ./script How do you omit this? I am using CentOS 5.6 x64. I want to run it this way script
3
votes
2answers
3k views

From shell, killing a process if wallclock runtime exceeds some predetermined value

I want to start a process from a shell script, allow it to interact with the user (so I cannot just background it, grab the PID, launch sleep followed by sanity checks and kill), but if it is still ...
4
votes
2answers
383 views

Saving tab completion possibilities to a file

Instead of displaying all possibilities on terminal screen, as in: $ ls /etc/<TAB> Display all 230 possibilities? (y or n) I want to save all possibilities to a file. ls /etc/ > file.txt ...
1
vote
1answer
465 views

Changing file extensions [duplicate]

Possible Duplicate: Renaming multiple files (changing extension) Suppose I have a bunch of files with the extension .x and I want to change them so that they have the extension .y. I know $ ...
5
votes
3answers
4k views

Print shell arguments in reverse order

I am a bit stuck. My task is to print the arguments to my script in reverse order except the third and fourth. What I have is this code: #!/bin/bash i=$# for arg in "$@" do case $i in ...
0
votes
1answer
293 views

Non printing characters

I would love to get the mappings to work for keyboard shortcuts shown here http://ascii-table.com/ansi-escape-sequences.php I have the hang of color but for some reason nothing else seems to work!
7
votes
2answers
4k views

Can I automate tar's multi-volume-feature?

Ok, so I've just had a read through this page after a way to improve my current backup solution on my Debian server. Tar seems to be offering a quite nice multi-volume feature, although when I try it ...
20
votes
1answer
3k views

Execute bash scripts on entering a directory

What is the best way to execute a script when entering into a directory? When I move into a new directory I would like bash to execute the projectSettings.bash script much like RVM does.
2
votes
2answers
2k views

How do I cause a watchdog reset of my embedded Linux device

Is there a command like vi > out vi | out That I could use to cause a watchdog reset of my embedded linux device?
8
votes
1answer
3k views

Alias a command to run in the background

I'd like a keyboard shortcut to work as so: > e foo.txt to expand as > emacs foo.txt & It's simple to use alias e=emacs, but how do I insert the & after the filename? I realize it ...