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

2
votes
3answers
349 views

In bash shell, how to insert the previous line inside the current line?

In bash, how to expand the !! in command line while interactively editing the command inside shell? I am working in vi edit mode. When typing a new command line, I want to introduce the previous line ...
9
votes
4answers
5k views

using parallel to process unique input files to unique output files

I have a shell scripting problem where I'm given a directory full of input files (each file containing many input lines), and I need to process them individually, redirecting each of their outputs to ...
4
votes
1answer
149 views

How to find bash in a portable way

When we write shell scripts we do this: #!/bin/bash But What if bash is in /usr/bin/? How can we find it in a portable way inside script? I did this, but it gives error: #!which bash
3
votes
1answer
10k views

Using regex inside if clause in bash

Look at this if block: #!/bin/bash str="m.m" if [[ "${str}" =~ "m\.m" ]]; then echo "matched" else echo "not matched" exit 1 fi exit 0 This should print "matched", but it doesn't. ...
2
votes
2answers
1k views

using read inside if clause - bash

I have a script: #!/bin/bash if [[ read -t 10 -sp "Enter Password: " passwd ]]; then echo -e "\nPassword: ${passwd}" else echo -e "\nInput timed out" >&2 exit 1 fi exit 0 But ...
1
vote
3answers
584 views

Problem with bash script executed from website

I have just begun writing scripts in bash and I am putting some of them on my web server (whihc is located on my virtual Debian 6.0.4 machine). I have installed lighttpd on this machine.and when I ...
24
votes
2answers
3k views

Why is bash's prompt variable called PS1?

The environment variable for the bash prompt is called PS1 (usually set in ~/.bashrc). What does PS1 stand for? Is there a PS2?
1
vote
1answer
331 views

selective stdout , stderr and logging using the script command [duplicate]

Possible Duplicate: Show only stderr on screen but write both stdout and stderr to file stdout , stderr and logging using the script command cat test.sh: rm -v foo.tmp date pwd cat ...
2
votes
3answers
212 views

How do I easily update list of md5sums?

Sometimes I use an unreliable medium (flash) to store a good deal of data. To at least recognise bit flips I store a file with the md5sums alongside. This file is usually created by a variation of ...
67
votes
9answers
68k views

How to add a newline to the end of a file?

Using version control systems I get annoyed at the noise when the diff says No newline at end of file. So I was wondering: How to add a newline at the end of a file to get rid off those messages?
2
votes
3answers
224 views

Selecting latest files and grouping by name

I have a directory containing files of the following name structure. <device>.<yyyy-mm-dd-hh-mm-ss> I am working on a script that will retain the the last X copies of these ...
6
votes
3answers
1k views

Why are background jobs started by my shell living longer than the parent shell and controlling terminals?

It is commonly said that "&" puts the process into background execution, but that process would be killed when terminal is closed. But from what I see, everything I sent into background was ...
7
votes
3answers
5k views

Set Variable Environment Variables in bash (or other)

I want my script to read a file containing key/value pairs of environment variables to set, and then to set them. So far, I have this: #!/bin/bash cat $1 | while read kv do key=${kv%=*} ...
0
votes
1answer
475 views

Setting LS_COLORS and in a GNU Screen

Is there a way to set a GNU Screen LS_COLORS to that of the default non-screen terminal window? Is there .screenrc or .screen_profile, I don't understand what happens when a GNU Screen is ...
5
votes
1answer
1k views

Bash: Use an alias in a variable

I am writing a bash script that runs each of its arguments as a command. This works for commands in my PATH, but not for aliases. I can directly call an alias in the script, but I can't call an alias ...
2
votes
5answers
1k views

What do these commands mean?

What would be a more straight forward readable way of these commands? And why exit 255 and not exit 1? [ $# -eq 3 ] || { echo error ; exit 255 ; } grep -q "string" && exit 0
1
vote
0answers
126 views

Doubt on the value of PS1 environment variable [duplicate]

Possible Duplicate: What is $debian_chroot in .bashrc? In Bash, why is PROMPT_COMMAND set to something invisible? I logged into my computer from a normal user and executed the following ...
7
votes
3answers
13k views

Can I search bash history across all users on a server?

I want to see all bash commands that have been run on a Linux server across multiple user accounts. The specific distribution I'm using is CentOS 5.7. Is there a way to globally search .bash_history ...
10
votes
4answers
10k views

How to make the terminal display user@machine in bold letters?

I have seen in some screen-shots (can't remember where on the web) that the terminal can display the [username@machine /]$ in bold letters. I'm looking forward to getting this too because I always ...
5
votes
2answers
5k views

ulimit PICKLE: “Operation not permitted” and “Command not found”

I'm trying to increase the maximum number of open files for the current user > ulimit -n 1024 I attempt to increase and fail as follows > ulimit -n 4096 bash: ulimit: open files: cannot ...
7
votes
1answer
574 views

Why is bash extended-globbing variable substitution acting at the byte level?

I thought that bash variable substitution and globbing worked at character resolution, so I was rather surprised to see it acting at the byte level. Everything in my locale is en_AU.UTF-8 When ...
1
vote
4answers
428 views

FreeBSD is not Unix. But its Unix-Like Unix. Where is then the main Unix to read the source code?

I want to really understand System V, the main origin of Unix (not Unix-like nor modified Unix to Linux). The main origin which is very confusing and not really with care its written somewhere. Is it ...
1
vote
1answer
374 views

How to create a cron which finds/kills/clears old puppet runs?

I am a new user of bash/cron, and I was given a task to create a cron which finds/kill/ and clears old puppet runs that were not successfully installed. The more help the better, but I am more or less ...
1
vote
2answers
535 views

Proper way to use shebang for bash

What is the recommended options in bash's shebang? #!/bin/bash -e I currently have it as above. This sources $HOME/.bashrc. I don't want to source user's .bashrc/.profile as it might interfere ...
6
votes
1answer
177 views

Confusion about sed and '>'

The following command works fine: sed s/input/raw_input/ p.py >p2.py && mv p2.py p.py However, the following command turns p.py into an empty file: sed s/input/raw_input/ p.py >p.py ...
6
votes
2answers
2k views

Bash $PROMPT_COMMAND messing up scroll history display

I set up a PROMPT_COMMAND to display the current branch while I'm in a git repo. The relevant part of my .bashrc is: export PS1=" \[\033[34m\]\$\[\033[0m\] " export ...
1
vote
1answer
248 views

What is wget idiom for curl -o?

So I use code in some function like if [ ! -e $DOWNLOADS/$1 ]; then echo_run curl -L http://$4/$5/$1 -o $DOWNLOADS/$1 fi I wonder how to achieve the same thing without curl?
1
vote
2answers
482 views

What is wrong with my .bashrc PS1 line?

I think the screenshot should show what's going on. I open a shell, and dir colors don't work. I run bash again, and dir colors work. What's going on?
1
vote
2answers
1k views

Script to create files in a template

I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this: function newsite() { mkcd "$*" # mkdir and cd into it ...
12
votes
2answers
682 views

Bash syntax highlighting of subshells

Considering the large amount of questions which turn out to be related to subshells in Bash ("Why doesn't my variable increment in this piped while read loop?"), I just thought it would be very nice ...
2
votes
1answer
325 views

Why doesn't my new cygwin .bashrc interactive check work?

I just updated Cygwin and the new .bashrc contains this line right at the top: echo "BEFORE TEST" # If not running interactively, don't do anything [[ "$-" != *i* ]] && return echo "AFTER ...
15
votes
1answer
2k views

removing or clearing stack of popd/pushd paths

After pushding too many times, I want to clear the whole stack of paths. How would I popd all the items in the stack? I'd like to popd without needing to know how many are in the stack? The bash ...
5
votes
2answers
729 views

In bash, feed output of one command line-by-line into another command

I have the following bash command which fetches and block XML from a single column in mysql and feeds it into xmllint to prettify it. mysql --format csv --skip-column-names -e "select xmldata from ...
6
votes
1answer
569 views

Two pipes to one command

I am little bit confused by the following syntax. Although it works, It do not understand why it works. It seems, like there are two pipes attached to the diff command. But isn't there only one STDIN? ...
5
votes
3answers
1k views

Is there a more elegant way to count words and assign that count to variables?

I have a script: #!/bin/bash /root/xiotech status > xiostatus.tmp SyncCount=$(grep -c Sync xiostatus.tmp) PauseCount=$(grep -c paused xiostatus.tmp) CopyingCount=$(grep -c Copying xiostatus.tmp) ...
3
votes
4answers
6k views

Show files from the last 2 days on a mounted ntfs system?

What's exactly the command to show files younger than 2 days? I thought about something like this: $ find / -mtime -2 ...but I'm not sure how to print the date of the found files. My target is to ...
5
votes
1answer
391 views

Text to movie from commandline

I need a script called myslide which does the following: myslide -f 15 -t 20 "Hello World" produces a movie file (to be played by mplayer), which just displays "Hello World" in the center of the ...
3
votes
2answers
2k views

Invert results for “for in * do”-loops [duplicate]

Possible Duplicate: How do I reverse a for loop? Is there an easy way to invert a for in loop? For a script I want to process files in their reverse order. So instead of: for file in ...
9
votes
4answers
1k views

Windows shell Escape key (delete whole line) equivalent in Bash

In Windows command line (powershell and cmd), when you press Esc key while on a line, whatever you have typed at the prompt is removed. I found that pressing Esc key at bash prompt does nothing. ...
4
votes
2answers
194 views

bash script works with in debug only

I'm trying to remove characters from a file name. files #ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac Peter, Paul & Mary - The Very Best of Peter, Paul and ...
2
votes
2answers
348 views

Simultaneously move long list files to new location

I'm using a wonderful program called ExifTool to recursively rename a large batch of files. Here is example usage: $ exiftool -r -ext JPG '-FileName<CreateDate' -d %Y%m%d_%H%M%S.jpg . Error: ...
183
votes
10answers
21k views

In Bash, when to alias, when to script, and when to write a function?

It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing. But people shouldn't need 10 years for this. If I were just ...
11
votes
3answers
12k views

How to escape quotes in shell?

I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to ...
6
votes
4answers
2k views

How does Bash path completion work with sudo?

Tab path completion does not work (at least on Ubuntu and AFAIK Arch) with sudo mount <whatever> The iso file I am trying to mount is not in /etc/fstab. If I just type mount <whatever> ...
3
votes
2answers
912 views

Trying to run oprofile on ubuntu kernel but cannot find vmlinux file

I am trying to run oprofile on my ubuntu host but cannot find the vmlinux file. The set up sfor oprofile needs this file: As given here : ...
0
votes
2answers
689 views

How do you wrap executable commands so that they work in an alias or function?

I'm still getting around the quirks of shell scripting, but I feel like I'm getting a little more comfortable with it. I've been trying to create an alias to generate a tar file that I have to create ...
3
votes
0answers
527 views

How to improve this backup script? [closed]

I wrote this backup script. I run rsync, tar and a dump of mysql. I'd like to add some features like email alert or some kind of statistic. Here is the script: #!/bin/sh DATE=`date +%D-%T` ...
4
votes
2answers
5k views

Running a command on the remote host with interactive SSH (conditionally)

I would like to be able to automatically run a command on a remote host each time I log into that host, but within the current interactive SSH session. Something like ssh user@remotehost [run do.sh] ...
11
votes
4answers
973 views

How can I source the bashrc file every time I 'clear'

This might be a bad idea. The more I think about it the more I come to the realization that I probably shouldn't do it... but I've been trying and failing so I REALLY want to know how to do it, even ...
10
votes
4answers
9k views

find -exec in bash script with variable expansion

I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. ...