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

91
votes
3answers
13k views

What does “rc” in .bashrc stand for?

Is it "resource configuration", by any chance?
3
votes
2answers
168 views

How can I display the time when a command was executed in my bash prompt?

Currently my bash prompt looks like this $ echo $PS1 # \[\e[34m\][\t]\[\e[0m\] \[\e]0;\w\a\]\[\e[34m\]\u@\h: \[\e[34m\]\w\[\e[0m\]\n$ $ The problem is that \t will only display the time when the ...
5
votes
2answers
780 views

How to make sure that I use the latest version of bash?

I just setup bash v4.1.0 on my machine. The old version is under /bin/bash. Is there a way to use the newer version of bash without replacing the old one from /bin? I want the newer version to be ...
4
votes
1answer
405 views

What are the new features available to bash 4?

I was using bash3 up to now, and just got a copy of the latest version $ ./bash --version GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. ...
13
votes
4answers
2k views

Share aliases and PATH setting between zsh and bash

The shell that I normally use is zsh. I have several aliases to enable color in some programs such as ls and grep. I've also set my custom path so that I can execute programs in non-standard place ...
6
votes
5answers
556 views

How do you recall the last (n-th?) passed argument of the previous command you used with bash?

Often times I issue different commands on the same file. For example: $ youtube-dl aB54c4p0eo #I made this video id up on the spot $ mv aB54c4p0eo.flv kittens.flv $ vlc kittens.flv $ rm kittens.flv ...
5
votes
1answer
950 views

How to get a persistent “history”-file even after a non-clean shutdown?

I am trying Ubuntu Server 10.10 in VirtualBox. I like that the commands I run is saved in a "history"-file that can be shown with the history command. But if I just turn off VirtualBox without the ...
19
votes
2answers
3k views

What is the bash shortcut to change to the previous directory?

Sadly, I only learned about this last year by stumbling upon it randomly on the internet. I use it so infrequently that I always forget what it is by the time I need it again. How do you change to ...
5
votes
2answers
1k views

How similar is Apple's terminal.app to a bash terminal on Linux?

I know that Apple's Terminal.app provides a bash shell. Are there any differences between this and a bash on Linux?
1
vote
3answers
198 views

Is it possible to know when you're at the first bash prompt of a terminal?

This is sort of a contiunation of my last question: printing saving the last bash input command Now I want to know if it's possible to know when you're at the first bash prompt of a terminal. So I'm ...
4
votes
1answer
2k views

Printing (saving) the last bash input command

How can I get the last executed command from bash? I know that !!:p prints the last command, but it seems I can't use that anywhere except the bash prompt. I tried echo !!:p but it prints ...
1
vote
1answer
1k views

What strings should I look for in /var/log/auth.log?

I wrote a bash command to scan /var/log/auth.log for messages occurring on the current day indicating unauthorised access. Currently it just fetches messages matching BREAK-IN and unauthorized. What ...
33
votes
1answer
9k views

What is $debian_chroot in .bashrc?

What is the debian_chroot variable in my bashrc file? and what is it doing here? PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
36
votes
4answers
4k views

Alternative to .bashrc

Is ~/.bashrc the only place where I can specify user specific ENV Variables, aliases, modifications to PATH variable, etc? I ask because it seems that ~/.bashrc would be BASH only...
27
votes
5answers
5k views

How to echo a bang!

I tried to create a script by echo'ing the contents into a file, instead of opening it with a editor echo -e "#!/bin/bash \n /usr/bin/command args" > .scripts/command The output: bash: ...
7
votes
4answers
642 views

Changing the bash prompt

Where is the setting that determines what the bash prompt looks like? Specifically on Arch, but I'm sure others would like to know for other distros too if it's different. Speficially I'd like to use ...
6
votes
1answer
1k views

What does the 'a' attribute in lsattr mean?

I was trying to remove some old history from my .bash_history file, but I was receiving this message: [john ~] /home/john $ mv .bash_history .bas mv: impossible to move `.bash_history' to `.bas': ...
19
votes
3answers
18k views

CLICOLOR and LS_COLORS in bash

I have the following setup in .bashrc for coloring of listings. export CLICOLOR=1 export ...
1
vote
4answers
1k views

Toggle between dvorak and qwerty

I've recently started to learn the dvorak keyboard layout, but I still need to use qwerty sometimes. I'm looking for a script to toggle between the two keyboard layouts. Also, I'd like to invoke ...
4
votes
2answers
5k views

How to get a program running with root privileges without using su or sudo

I have a bash script that needs to run with root privileges, but must be invoked by the normal user. Difficult part is that the script should not ask for a password, and I don't want to use the ...
8
votes
1answer
958 views

Bash autocomplete in ssh session

It seems that bash doesn't want to autocomplete commands (what's annoying me right now is not autocompleting apt-get) when I'm logged into my machine from SSH. Is there some setting that will allow ...
3
votes
3answers
2k views

Substitute part of text file using bash script

I'm writing a shell script (bash) to fetch and build several bits of software. The script also writes several small config files and needs to alter a couple of pre-existing config files. What is the ...
20
votes
3answers
11k views

How to remove “You have mail” welcome message

When I open up my terminal it says "you have mail", anyone has any idea of why? I am running OS X, but since it too is based on Unix and relies on files such as bashrc, bash_profile etc. I thought ...
2
votes
4answers
1k views

How do I force the user to become root

I have written a bash script for use on my ubuntu box. Now I would like to prevent running this script under my own user and only able to run it as root (sudo). Is there a possibility to force this. ...
0
votes
0answers
147 views

How to mimic zsh named directories with bash [duplicate]

Possible Duplicate: bash directory shortcuts zsh has the concept of named directories, so you can say in ~/.zshrc c=/home/fschmitt/svn/plugin_root : ~c and later use this short cut in ...
3
votes
2answers
873 views

How can I simulate keyboard shortcuts in a bash alias?

For example, one of my bash aliases is this alias p='clear;ls -lt;pwd;' clear also clears the history which I don't want. I just want to clear the screen momentarily. Ctrl+L however does exactly ...
8
votes
3answers
16k views

How do I count the number of occurrences of a word in a text file with the command line?

I have a large JSON file that is on one line, and I want to use the command line to be able to count the number of occurrences of a word in the file. How can I do that?
1
vote
3answers
330 views

build script: how to implement a “skip previously completed step”

I'm trying to create a build script for GCC (which works, for now), but I would like to be able to skip rebuilding all the prereq libraries when I'm only updating GCC/binutils for example. I thought ...
2
votes
1answer
942 views

Array of string expanded to path?

Suppose I have the following initialization of bash array: my_array=( "/usr/bin" "/usr/lib/*.so" ) If I do iteration using: for array_item in ${my_array[@]} do ... done Then the ...
4
votes
3answers
242 views

Randomise or shred memory of an application

Is it possible to randomise or shred memory of a particular application just after its life ends, or better, whenever it deallocates some memory? A command-line utility like this would be perfect: ...
5
votes
2answers
1k views

How to suspend and resume processes

In the bash terminal I can hit Control+Z to suspend any running process... then I can type fg to resume the process. Is it possible to suspend a process if I only have it's PID? And if so, what ...
1
vote
2answers
274 views

Problematic build script with quotes

Hi I'm trying to create a build script that executes these commands: cd libiconv ../../src/libiconv/configure --prefix=/home/ruben/mingw64/build/gcc-libs \ ...
0
votes
0answers
325 views

bash: recall command by typing some characters of it [duplicate]

Possible Duplicate: best way to search my shell's history In MSDOS I have the option to start typing some characters of a previous command and then pressing F8 it will search the ...
2
votes
2answers
542 views

Script for ssh Agent Management: Is this adequate? Any bugs?

The following is something I use to manage my ssh agent settings. #!/bin/echo "Must source this:" ## Ensure that ~/.ssh/env contains valid values unset SSH_AGENT_PID SSH_ENV_REFRESH [ -r ...
3
votes
5answers
4k views

How to find image files by content

I have a list of files and I need to find all the image-files from that list. For example, if my list contained the following: pidgin.tar.gz photo01.jpg picture01 screenshot.gif invoice.pdf Then I ...
3
votes
2answers
213 views

Specifying which git repo to use

I have a bash script, called cgit, that acts as git for one specific git repo (located at /.git): #!/bin/bash cd /; sudo git $@ > /dev/stdout I use it to keep track of imporant system files: ...
8
votes
1answer
3k views

How to specify a custom autocomplete for specific commands? [duplicate]

Is there a way to have bash know exactly what to display when you double tab? For example I have a python script scpy which requires a couple arguments. For example like apt-get, if you double tab ...
8
votes
3answers
7k views

How do I split the $0 variable to find directory and relative paths in bash?

The $0 variable contains the path info of the script. How can I change the path info to absolute path? I mean how to process ~, ., .. or similar? How can I split the path info into directory and ...
8
votes
3answers
2k views

Change the PS1 color based on the background color?

I learned that I can change the format of PS1, especially the color of the string. Then, is it possible to change the color based on the background color of the shell? Or, how can I detect the ...
6
votes
3answers
1k views

bash PS1 setup

I'm trying to make PS1 configured as follows. Green="\[\e[32;1m\]" Red="\e[0;31m" Purple="\e[0;35m" STARTCOLOR="\[\e[40m\]" ENDCOLOR="\[\e[0m\]" export PS1="$STARTCOLOR$Green\u@$Purple\h ...
3
votes
2answers
870 views

Capture multi-line output of a bash builtin

Normally, bash is able to assign multi-line output of a command: L=`ls` This works from both interactive shell and scripts. But it appears the output of a builtin can't be captured in a variable: ...
4
votes
2answers
929 views

dash compatibility to bash

Wikipedia says that dash executes faster than bash. My question is, if I set /bin/sh to dash, will all scripts that use /bin/sh in their shebang line that was intended for bash work under dash?
16
votes
6answers
14k views

Grabbing the extension in a file name

How do I get the file extension from bash? Here's what I tried: filename=`basename $filepath` fileext=${filename##*.} By doing that I can get extension of bz2 from the path /dir/subdir/file.bz2, ...
5
votes
1answer
239 views

Whenever I type some wrong command, my terminal tries to run that command in the background

Something strange started happening to my terminal. Whenever I type some wrong command it tries to run that command in the background. hegeek@colinux: ~# l [9]+ Stopped l thegeek@colinux: ~# ...
2
votes
3answers
3k views

Bash eval array variable name

Here is my bash case: First case, this is what I want to do "aliasing" var with myvarA: myvarA="variableA" varname="A" eval varAlias=\$"myvar"$varname echo $varAlias Second case for array variable ...
36
votes
6answers
26k views

Why doesn't my Bash script recognize aliases?

In my ~/.bashrc file reside two definitions: commandA, which is an alias to a longer path commandB, which is an alias to a Bash script I want to process the same file with these two commands, so I ...
12
votes
7answers
7k views

bash directory shortcuts

When I type cd ~foo, I'd like bash to take me to some directory foo as a shortcut for typing the full directory path of foo. and I'd like to be able to cp ~foo/bar.txt ~/bar.txt to copy a file from ...
5
votes
1answer
5k views

Remote for-loop over SSH

I have the following in a script for server in ${servers[@]}; do echo ${server} ssh user@${server} "for i in /tmp/foo* ; do echo ${i}; done" done But it doesn't work. Weird thing, I see $I amount ...
1
vote
1answer
94 views

How do I make the “1.9.2” Ruby string point to the final release with RVM?

I'm using RVM to manage my Ruby environment on OSX, and currently it's interpreting '1.9.2' as ruby-1.9.2-rc2 instead of the final release. How can I update this to make it behave as expected?
4
votes
3answers
8k views

Convert ascii code to hexadecimal in UNIX shell script

I'd like to convert ASCII code (like - or _ or ., etc.) to hexadecimal representation in the Unix shell (without bc command), eg : - => %2d. Any ideas?