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
2answers
3k views

bash nested case syntax and ;; terminators

Have I got enough (or perhaps too many) ;; terminators in this bash script containing nested case's? case "$1" in OK) # Nothing needs done echo -n "OK:1" ;; CRITICAL) case "$2" in ...
4
votes
1answer
3k views

dot file not sourced when running a command via ssh

When I run my program interactively, it works fine: ssh somehost $ ~/some/path/somescript.py When I run my program over ssh directly, it doesn't work. The variable PYTHONPATH is not set, because ...
7
votes
2answers
1k views

Is there a correct way to list the subdirectories of the current directory?

I can find the subdirectories of a directory by ls -d -- */ or ls -l | grep "^d" but both of these seem indirect, and I would imagine that there would be a standard way to find just the ...
6
votes
3answers
1k views

Tab-completion for Mercurial in Bash?

Using Subversion on the command-line, it intelligently tab-completes available subcommands, etc: $ svn c<tab> cat checkout cl co copy changelist ci ...
0
votes
1answer
562 views

Force wget to download only from HTTPS?

wget https://skype.com -O - > /dev/null isn't good. I just want to create a short bash script to check that an HTTPS cert is valid or no. i think wget doesn't connects if the cert is invalid. i ...
2
votes
2answers
492 views

I can create a file but I can't read from it

I've been using linux for a while, but I always had root access, so permission problems were no big deal. But now I don't have root access and it's driving me mad. I have a ssh access to a web ...
2
votes
2answers
245 views

Replace all files with identical hash

I want to replace all files in a target path with the same name as original.file AND the same hash as orignal.file with new.file. What's the command to do this? Say I have updated the contents of a ...
0
votes
3answers
1k views

Why can't I run this script?

$ sh bashtrrrrrr # whats my pub. ip? bashtrrrrrr: line 19: unexpected EOF while looking for matching `'' bashtrrrrrr: line 20: szintaktikai hiba: váratlan fájl vég $ cat bashtrrrrrr #!/bin/bash ...
19
votes
3answers
6k views

Duplicate entries in $PATH a problem?

I source bashrc's of few of my friends. So I end up having duplicate entries in my $PATH variable. I am not sure if that is the problem for commands taking long to start. How does $PATH internally ...
7
votes
1answer
1k views

Most efficient way to run 2 while loops

Currently I use two different while loops to start my window manager, dwm, and the status bar that prints system info to it. My solution at the moment is to run them consecutively in the same script, ...
8
votes
3answers
22k views

Recursive chmod only folders or only files via script or nautilus menu?

This has been discussed before here. What I'd like to know is how to turn these: Recursive chmod only files within this folder: find . -type f -exec chmod 0600 {} \; Recursive chmod only folders ...
1
vote
2answers
246 views

How can I add a space automatically after every command I type in bash?

Due to some unknown reason I am not able to edit/delete the last character of any bash command from the bash history i.e. when I access last bash command using 'up' arrow I cannot change or delete the ...
3
votes
2answers
989 views

Bash and Tab Auto-complete

I recently put Fedora Core 15 on my system, and I've had a behaviour change that I can't figure out. Using Tab-Complete in the BASH shell works fine except when I use the $HOME variable. If I type cd ...
8
votes
5answers
2k views

Bash CD up until in certain folder

I do a lot of work in Magento, and so do a lot of the people I work with, and it gets annoying to have to type: cd ../../../../../../ To only find you're still a few directories from your root ...
7
votes
2answers
1k views

Precedence of stdin and stdout redirection in Bash

My question is about redirection precedence is bash. Suppose you have a command: cmd1 < cmd2 > cmd3 Would it translate to: (cmd1 < cmd2) > cmd3 Or cmd1 < (cmd2 > cmd3)
4
votes
2answers
914 views

Strange Character in my Bash prompt?

I'm somewhat new to Bash prompts, but I was finally able to get things somewhat working. However, I have a strange character at the beginning of my prompt: Here's my actual PS1 prompt: ...
2
votes
2answers
367 views

My alias parser works on the command line but not from a script

I'm trying to create a simple script that will dump all my aliases into a file that bash can load when it starts up, while making sure the alias of - to popd works properly: alias -p | sed 's/alias ...
17
votes
2answers
12k views

Is it possible to set Gnome Terminal's title to “user@host” for whatever host I'm connected to?

I'd like to set the terminal title to user@host so I can easily tell which machine I'm connected to from the window title. Is there a way to do this from SSH or from GNOME Terminal?
1
vote
3answers
102 views

Check that there was an error one-liner in script

I want to put an error checking solution to my script, it looks like this: ! [ `echo $?` != 0 ] || echo "omg, st went wrong, CTRL+C? `read`" My goal is when this line runs it check the "$?" - if ...
5
votes
4answers
2k views

find not recursive when file at top

Imagine a source tree. There are xml files everywhere. But since there is a XYZ.xml at the root of this tree it won't find my xml files. find -iname *.xml returns ./XYZ.xml instead of ...
6
votes
1answer
490 views

How to make bash history prefix-sensitive?

How can I make pressing up/down on bash bring up the last command that started with the prefix I already entered? E.g. $ ls foo $ echo hello $ ls <UP_ARROW> Clicking UP after entering ls ...
5
votes
2answers
334 views

Bash, curious about echo $variable

I was hacking at a small script earlier and noticed something I can't explain. Running this command (time wget --spider http://www.google.co.uk/) 2>&1 | egrep 'real|response' gives me ...
2
votes
2answers
3k views

Using sed to replace a line with many special characters?

I am writing a rather massive script for a project and one of the issues I am running into before I can complete it is using the sed command. I am trying to find a line that has (located in ...
14
votes
6answers
10k views

Execute a specific command in a given directory without cd'ing to it?

Is there a way to execute a command in a different directory without having to cd to it? I know that I could simply cd in and cd out, but I'm just interested in the possibilities of forgoing the extra ...
4
votes
1answer
3k views

Debugging shell scripts: Syntax checking without executing

Is there some option I can give to just check the syntax of a [bash] shell script to check the syntax of it, but not actually execute anything nor cause any potential damage?
25
votes
9answers
35k views

Is there a way to get the min, max, median, and average of a list of numbers in a single command?

I have a list of numbers in a file, one per line. How can I get the minimum, maximum, median and average values? I want to use the results in a bash script. Although my immediate situation is for ...
9
votes
1answer
7k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < ...
1
vote
1answer
2k views

Can you specify a separate trap in a subshell created with ()?

I'm writing a script that starts a subshell to go off and do some work. In a special case, the script needs to tell the subshell to cleanly stop what it's doing and exit early. However, my ...
1
vote
2answers
1k views

Is there a BASH command for copying all files from a directory tree and putting all the files in a single directory?

I have a ton of notes categorized into folders, but I think it might be better to put them all into one folder instead. Is there an easy way to do that?
27
votes
5answers
3k views

Better way of accepting variations of ‘Yes’ from a shell prompt

Usability testing of a shell script I wrote found that people had different expectations on how to answer a question that expected ‘yes’ as the answer. See variations in the below code example. ...
0
votes
2answers
439 views

Better solutions for this: tail -200 /var/log/messages | head -100

Are there any better solution to this? tail -200 /var/log/messages | head -100 Are there other methods to achieve this output? (not more complex, I'm looking for simpler solutions!)
6
votes
3answers
2k views

Is there a way to find a file in an inverse recursive search?

So say I'm in a directory that is deep within a file structure, such as /home/cory/projects/foo/bar/bash/baz I know that in either the current folder baz or one of the folders above me (such as ...
2
votes
2answers
6k views

Multiple path environment variable setup lines with bash

I have very long export PATH=A:B:C .... Can I make a multiple lines to have more organized one as follows? export PATH = A: B: C:
4
votes
2answers
934 views

Why can't I pgrep a process?

$ ps aux | grep -i ssh USER 4364 0.0 0.0 9004 1032 ? Ss 12:20 0:00 ssh -v -fND localhost:4000 USERNAME@SERVER-IP-ADDRESS $ pgrep localhost:4000 Why doesn't this work?
9
votes
4answers
3k views

Batch delete exif info

How can I recursively remove the EXIF info from several thousand JPG files?
2
votes
1answer
456 views

Is there some kind of “patterns” when coding bash scripts? [closed]

In Java, we have Javadoc and some different styles when programming. In Python, there's pep8. I'm creating some bash scripts for my own use, and would like to know from you, experienced bash users, ...
4
votes
2answers
3k views

In bash, how to convert 8 bytes to an unsigned int (64bit LE)?

How can I 'read/interpret' 8 bytes as an unsigned int (Little Endian)? Perhaps there is a Bash-fu magic conversion for this? UPDATE: It seems that something got cross-wired in the interpretation of ...
1
vote
1answer
140 views

How to bash-complete output of two arbitrary commands at the same time

Here goes: function _command() { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ "$COMP_CWORD" -ge "2" ]; then COMPREPLY=($( compgen -W '$(pwd)' -- "$cur" ) ) ...
3
votes
1answer
3k views

auto accepting rsa key in bash script

I have done a little googling and have not come up with a clear answer to this question. I was wondering if someone could help me out with this issue. Is there a way to auto accept any RSA key inside ...
5
votes
1answer
3k views

Dollar sign interpolation inside quotes in bash

I am running this little test script I wrote : #!/bin/bash TESTCASE=$@ testHarness <<runTest $TESTCASE runTest from the command line : ./test.sh "1092$212" but the dollar sign is being ...
5
votes
2answers
6k views

loop curl get request bash

I'm trying to automate a curl script and eventually make it loop also. I found that I can't use any loop like: for i in `cat authors` do curl *line here* ...
2
votes
2answers
377 views

bash quotes expansion puzzle

My script looks like: opts="-x ''" curl http://somepage $opts I want the string in $opts appended to the command. I use bash -x test.sh to check the expansion and see that the the single-quotes are ...
4
votes
1answer
253 views

Preventing use of `cd ..` in bash?

I have set up an alias in my .bashrc as follows: alias u='cd ..' All is well in my world... until I type cd .. and cringe that I did not use my incredible new alias. In fact, with this particular ...
1
vote
2answers
676 views

writing a command transcript to file

Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze. Echo commands + standard output + standard error to a file. Prefix with ...
14
votes
2answers
807 views

How can one time out a root shell after a certain period of time?

Is there a way to 'time out' a root shell (for example, in gnome-terminal) so that after a certain amount of time not issuing any commands, the shell exits? I'm searching for a solution that works in ...
1
vote
1answer
320 views

How to have autocomplete ignore a specific completion

I've got auto-completion working for bash. When I type part of a program name, and then TAB, I get the full command. Works like expected, no complaints. However on my setup I've got an alias defined ...
5
votes
2answers
851 views

Will I be able to build LFS using dash and mawk?

I decided that I want to learn more about Linux and try building LFS. I'm using Ubuntu 11.04 as host system and Ubuntu uses dash and mawk by default. I've changed mawk to gawk, but considering that ...
3
votes
1answer
349 views

BC - output normal form?

I have a big number: 2923174917395723957 that would be: 2,923*10^18 are there any parameters in bc that will give this OUTPUT? e.g.: $ echo '2923174917395723956 + 1' | bc 2,923*10^18 $ Or ...
2
votes
4answers
710 views

BC - no “\\n” at the end + start with zeros?

This is a bc output, e.g.: Input: echo "scale=10; BLA-BLA-HERE-NOT-IMPORTANT" | bc Output: .3708446283953709207058828124021300754352578903651372655882743141882\ ...
14
votes
2answers
7k views

How to get the output inside `screen` out to a script?

I have a screen instance running, and I would need to execute some code inside the screen, and get the result out to my script. The first part is quite easy, I just screen -S session_name -X eval ...