Questions tagged [bash]

Bash is a free shell for Unix-like operating systems from the GNU Project.

A shell is a command line environment that allows advanced scripting. It is provided on many (all?) operating systems based on or inspired by Unix. Notable OS's are Mac OS X, BSD, Solaris and the different flavours of Linux.

Bash is such a shell created in 1987 to fix some of the problems of the older Bourne Shell. The Bash command syntax is a superset of the Bourne shell command syntax and almost all Bourne shell scripts can be executed by Bash without modification. Bash stands for Bourne Again Shell.

Website: http://www.gnu.org/software/bash/bash.html

11906 questions
829
votes
13 answers

What does 'source' do?

$ whatis source source: nothing appropriate. $ man source No manual entry for source $ source bash: source: filename argument required source: usage: source filename [arguments] It exists, and it is runnable. Why isn't there any documentation about…
Andrea Ambu
  • 8,958
572
votes
6 answers

Difference between .bashrc and .bash_profile?

What's the difference between .bashrc and .bash_profile and which one should I use?
cfischer
  • 9,163
519
votes
11 answers

What is the home directory on Windows Subsystem for Linux?

When I start bash on Windows Subsystem for Linux, it drops me in the directory /mnt/c/Users/ When I ls this directory, I see the directories Desktop, Documents, etc. that I can see are in C:\Users\ using the Windows File…
bcf
  • 5,333
502
votes
7 answers

What is the difference between executing a Bash script vs sourcing it?

What is the difference between executing a Bash script like A and sourcing a Bash script like B? A > ./myscript B > source myscript
Scottie T
  • 5,221
472
votes
11 answers

How do I add text to the beginning of a file in Bash?

Hi I want to prepend text to a file. For example I want to add tasks to the beginning of a todo.txt file. I am aware of echo 'task goes here' >> todo.txt but that adds the line to the end of the file (not what I want).
user479534
  • 4,931
444
votes
19 answers

How to encode base64 via command line in macOS/OS X?

Is there a terminal command in macOS/OS X which will base64 encode a file or stdin?
Josh
  • 9,947
415
votes
21 answers

How do I detach a process from Terminal, entirely?

I use Tilda (drop-down terminal) on Ubuntu as my "command central" - pretty much the way others might use GNOME Do, Quicksilver or Launchy. However, I'm struggling with how to completely detach a process (e.g. Firefox) from the terminal it's been…
AnC
410
votes
13 answers

How can I search the bash history and rerun a command?

Can I search history in bash and run the result?
409
votes
4 answers

Go back to previous directory in shell

Is there a way to go back to previous directory we were in using bash,tcsh without using pushd/popd ? I'd like to type something like "back" and got returned to the previous directory I was in. Edit: "cd -" works, but only for current and previous…
Lydon Ch
  • 6,289
397
votes
7 answers

How to iterate over lines in a variable in Bash?

How does one properly iterate over lines in bash either in a variable, or from the output of a command? Simply setting the IFS variable to a new line works for the output of a command but not when processing a variable that contains new lines. For…
379
votes
11 answers

chown is not changing symbolic link

I'm trying to change the user/group of a symbolic link with the command: $ chown -h myuser:mygroup mysymbolic/ But it's not changing. I'm logged in as root. The current user/group is set to root:root. What went wrong?
rizidoro
274
votes
5 answers

Linux Bash Script, Single Command But Multiple Lines?

I have the following script I wrote by searching Google, and it backs up my Linux system to an archive: #!/bin/bash # init DATE=$(date +20%y%m%d) tar -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz --exclude=/proc --exclude=/lost+found…
Jay LaCroix
  • 2,761
254
votes
12 answers

What to do when Ctrl + C can't kill a process?

Ctrl + C doesn't always work to kill the current process (for instance, if that process is busy in certain network operations). In that case, you just see "^C" by your cursor and can't do much else. What's the easiest way to force that process to…
244
votes
6 answers

In bash, how do I escape an exclamation mark?

I want to do something like bzr commit -m "It works!". I can sort of escape the exclamation mark by doing bzr commit -m "It works\!". However, then my commit message includes the backslash. How do I escape the exclamation mark, while still ignoring…
Matthew
  • 15,036
243
votes
27 answers

Bash scripting: test for empty directory

I want to test if a directory doesn't contain any files. If so, I will skip some processing. I tried the following: if [ ./* == "./*" ]; then echo "No new file" exit 1 fi That gives the following error: line 1: [: too many arguments Is…
Anthony Kong
  • 5,318
1
2 3
99 100