2022 Developer Survey is open! Take survey.

Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

Filter by
Sorted by
Tagged with
43 votes
15 answers
28k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
user avatar
12 votes
3 answers
15k views

How to open multiple files from `find` output?

I know I can open multiple files found in a dir like so: find -name *.foo -xargs <command> {} \; This works, but when trying to open a bunch of textfiles in gedit at the same time, it opens ...
user avatar
  • 1,266
4 votes
6 answers
10k views

truncating file names

I have a folder that has a number of files all of a similar form as: Dropkick Murphys - 01 - Walk Away.mp3 Dropkick Murphys - 02 - Workers Song.mp3 And so forth... I want to convert them all so ...
user avatar
  • 2,195
42 votes
4 answers
10k views

aliasing cd to pushd - is it a good idea?

Is it a good idea to use the following alias: cd() { pushd $1; } in bash? I think this would be very useful, since I can then use a series of popds instead of just a cd - once. Is there any ...
user avatar
  • 33k
19 votes
2 answers
9k views

Change directory without typing cd?

Is it possible to make bash change directory in command line simply by typing that directory without any commands like cd? For example is it possible instead of writing this: $ cd /tmp I just want ...
user avatar
  • 300
114 votes
8 answers
40k views

How do I get bash completion for command aliases?

I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided ...
user avatar
  • 3,465
4 votes
5 answers
7k views

Does $SHELL store the path to the default shell in Linux?

My administrator says that my default shell is set to bash, but $ echo $SHELL /bin/csh $ Is the default shell related to the SHELL variable at all? Is not, what is the variable used for?
user avatar
  • 33k
11 votes
8 answers
38k views

What is your favourite shell script GUI/CLI editor and why? [closed]

I'm using vim for editing bash scripts currently, but I really need to set it up and/or install plugins. Plugin suggestions welcome. Either way, I'd like to see which editors/IDEs there are for this ...
user avatar
  • 191
80 votes
8 answers
28k views

put history command onto command line without executing it

I use !n where (n) is the line number for executing a line in the history file I want executed at the command prompt which I find via history|less. But there is a command line history event I wish ...
user avatar
  • 5,121
22 votes
3 answers
11k views

remove extra tilespace from a montage (ImageMagick) composite image?

I have a bunch of photos. They're all the same height, and I'm trying to put them together into a composite image using ImageMagick's montage program via Bash. The problem is that by default, the tile ...
user avatar
5 votes
2 answers
716 views

Simple "Variable" Bash File

I just want to make a bash file that takes a file name as a parameter. In that bash file, I want to take the name before the extension and have it as a "variable", to use in other places. For example, ...
user avatar
  • 215
41 votes
1 answer
11k views

Aliases vs functions vs scripts [duplicate]

This site says, "Shell functions are faster [than aliases]. Aliases are looked up after functions and thus resolving is slower. While aliases are easier to understand, shell functions are preferred ...
user avatar
  • 2,905
1 vote
5 answers
4k views

Debian sed: can't read

I'm trying to run a command to remove require_once from php files from here (code below), but I am getting the error: sed: can't read -: No such file or directory I am in the correct folder; what'...
user avatar
  • 111
7 votes
2 answers
432 views

How is a graphical application started from a bash session connected to that bash session?

When I start a graphical application from a terminal running bash, that application is somehow connected to that bash session. For example, when the applications dumps some text it will appear in the ...
user avatar
  • 25.3k
31 votes
1 answer
77k views

In Bash, are if [ -z "$1" ] and if [ "$1" = "" ] the same?

In Bash shell scripting, what is the difference (if any) between the following two statements? if [ -z "$1" ] if [ "$1" = "" ] I have found myself writing the second ...
user avatar
  • 4,333
4 votes
2 answers
4k views

How to write a script to execute files in multiple directories

How do I write a script to execute the files in multiple directories? The problem is this: I have many directories, and each has a data file to be read and analyzed by a python script (say, a.py). I ...
user avatar
  • 71
4 votes
1 answer
237 views

What is this construct in bash? mycommand(){dosomething;}

I actually found following one-liner on commandfu.com: cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; } I have not come across a similar ...
user avatar
  • 1,266
141 votes
5 answers
181k views

Understanding the exclamation mark (!) in bash

I used history | less to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did !22 at the command prompt and it worked -...
user avatar
  • 5,121
4 votes
2 answers
779 views

How does file descriptor re-assigment work?

In a way this question is a extension of another question. In bash you can do pretty neat stuff with file descriptors. Like { command > /dev/null } 2>&1 | grep filter; to grep on stderr ...
user avatar
  • 23.5k
2 votes
0 answers
374 views

How can I check which shell I am currently using? [duplicate]

Possible Duplicate: How to test what shell I am using in a terminal? An echo $SHELL will only display the value of the SHELL variable which would indicate the default shell on the system. But I ...
user avatar
  • 33k
5 votes
5 answers
8k views

Applying a regex to stdin

In programing we often see the use of Regular Expressions. One of the most common forms is: newText = text.replace( /regex/, 'replacementString' ) If stdin is text and stdout is newText, what would ...
user avatar
  • 23.5k
51 votes
8 answers
98k views

Using xargs with input from a file

Say I have a file with the following bob john sue Now these directly corrospond to (in this case) URL pattern such as http://example.com/persons/bob.tar, john.tar, sue.tar. I would like to take ...
user avatar
  • 3,526
12 votes
2 answers
96k views

./executable: cannot execute binary file

I have a script that works well when I ssh to the server to execute it myself, but has problems when Hudson, a continuous integration server, runs it. I am automating tests on an embedded linux ...
user avatar
  • 223
4 votes
1 answer
1k views

Is "export" needed when setting HISTIGNORE in bashrc files?

As I understand it, exporting an environment variable makes it available to any processes spawned from the current one. But the only processes that will be interested in the HISTIGNORE variable (and ...
user avatar
  • 143
5 votes
2 answers
3k views

Expand KDE activities concept to the shell

Sometimes, I use KDE, and one of the things that I like the most in KDE 4 is the activity concept. At work, it is very useful because I often work on several different projects during one day. ...
user avatar
  • 2,775
62 votes
9 answers
32k views

How to print only defined variables (shell and/or environment variables) in bash

The bash builtin command set, if invoked without arguments, will print all shell and environment variables, but also all defined functions. This makes the output unusable for humans and difficult to ...
user avatar
  • 25.3k
2 votes
1 answer
206 views

Stop cron script from destroying my mirrorlist with invalid data

I have to following cron script that runs daily. As you should be able to see from the code, it outputs the results from reflector to /etc/pacman.d/mirrorlist. $ cat /etc/cron.daily/update-mirrorlist ...
user avatar
  • 23.5k
327 votes
4 answers
79k views

What does "rc" in .bashrc stand for?

Is it "resource configuration", by any chance?
user avatar
  • 33k
6 votes
2 answers
542 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 ...
user avatar
  • 33k
5 votes
2 answers
2k 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 ...
user avatar
  • 33k
8 votes
2 answers
5k 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. ...
user avatar
  • 33k
25 votes
4 answers
13k 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 (...
user avatar
  • 19.4k
13 votes
5 answers
3k 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 ...
user avatar
  • 2,927
6 votes
1 answer
5k 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 ...
user avatar
  • 1,583
85 votes
3 answers
36k 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 ...
user avatar
  • 1,163
5 votes
2 answers
3k 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?
user avatar
  • 1,001
1 vote
3 answers
311 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 ...
user avatar
  • 12.3k
6 votes
1 answer
4k 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 ~/...
user avatar
  • 12.3k
1 vote
1 answer
3k 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 ...
user avatar
  • 1,463
54 votes
1 answer
17k 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\$ '
user avatar
  • 12.3k
131 votes
4 answers
63k views

Is there a ".bashrc" equivalent file read by all shells?

Is ~/.bashrc the only place to specify user specific environment variables, aliases, modifications to PATH variable, etc? I ask because it seems that ~/.bashrc seems to be bash-only, but other ...
user avatar
  • 23.5k
64 votes
6 answers
42k 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: !/bin/...
user avatar
  • 23.5k
9 votes
4 answers
2k 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 ...
user avatar
  • 12.3k
6 votes
1 answer
3k 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': ...
user avatar
  • 657
56 votes
3 answers
68k views

CLICOLOR and LS_COLORS in bash

I have the following setup in .bashrc for coloring of listings. export CLICOLOR=1 export LS_COLORS='no=00:fi=00:di=00;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;...
user avatar
  • 7,700
4 votes
5 answers
6k 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 ...
user avatar
  • 23.5k
8 votes
2 answers
18k 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 ...
user avatar
  • 23.5k
10 votes
1 answer
3k 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 ...
user avatar
  • 12.3k
4 votes
3 answers
3k 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 ...
user avatar