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: https://www.gnu.org/software/bash/bash.html.

11956 questions
839
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
  • 9,058
574
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,193
529
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/<username> When I ls this directory, I see the directories Desktop , Documents , etc. that I can see are in C:\Users\<username> using the Windows File…
bcf
  • 5,433
504
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,241
478
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,991
447
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,997
422
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
415
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,369
412
votes
13 answers

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

Can I search history in bash and run the result?
401
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…
384
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
285
votes
10 answers

Unix zip directory but excluded specific subdirectories (and everything within them)

I'm trying to zip a directory (on Unix via SSH) but I need to exclude a couple of subdirectories (and all files and directories within them). So far I have this: zip -r myarchive.zip dir1 -x dir1/ignoreDir/**/* That doesn't seem to work though. I…
sulman
  • 5,871
276
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,781
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…
247
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 there a…
Anthony Kong
  • 5,366
1
2 3
…
99 100