Questions tagged [bash]

The default Unix shell used by Terminal in macOS

Filter by
Sorted by
Tagged with
367
votes
7answers
266k views

How do I recompile Bash to avoid Shellshock (the remote exploit CVE-2014-6271 and CVE-2014-7169)?

Given that Bash 3.2 (the version shipped by OS X) is vulnerable to the remote execution exploit known as "Shell Shock" (CVE-2014-6271 and CVE-2014-7169) how do I rebuild Bash and secure my system ...
328
votes
11answers
171k views

git auto-complete for *branches* at the command line?

On my Linux machine I have autocomplete for branches with Git. [Note we are talking about git branch completion, not bash completion (e.g. commands, files, etc). Thus NOT Lane's answer at all] For ...
229
votes
3answers
181k views

What is the difference between .bash_profile and .bashrc?

To make an alias for the Terminal in OS X, you can either put the aliases in .bash_profile or .bashrc. What is the difference between the two and why would I choose to put aliases in one and not the ...
193
votes
13answers
353k views

Why doesn't .bashrc run automatically?

I put some alias commands in my .bashrc file, so that they might be loaded everytime I open a new Terminal window. Yet this doesn't happen. I have to select run script: in the Terminal>Preferences>"...
92
votes
2answers
150k views

Why doesn't Mac OS X source ~/.bashrc? [duplicate]

I found a lot of people figuring out why instruction similar to this : Put X to your ~/.bashrc and you can do Y don't work. It always turns out that Mac OS X's bash's startup files (or Mac's Bash ...
85
votes
5answers
204k views

Getting files, all at once, from a web page using curl

I would like to download the files, all at once, from the following page using curl: http://www.ime.usp.br/~coelho/mac0122-2013/ep2/esqueleto/ I tried curl http://www.ime.usp.br/~coelho/mac0122-2013/...
85
votes
2answers
147k views

How can I list and edit all defined aliases in Terminal?

A friend who owned my current Mac before me created a lot of alias commands. Is there a way to list all defined aliases and the command that is associated with them? And if so, am I able to edit ...
80
votes
4answers
25k views

Is it safe to upgrade Bash via Homebrew?

I'm new to OS X. I'm running OS X Lion on a MacBook Pro. Is it safe to upgrade the bash shell using Homebrew: $ brew install bash If safe, how do I make it the default instance of the shell I run ...
77
votes
4answers
53k views

Is bash in OSX case-insensitive?

Are bash commands on OSX case insensitive? I type "which TR" and it shows /usr/bin/TR, though there is no such binary there. Same thing for other binaries, when capitalized. Or is Terminal.app maybe ...
72
votes
5answers
328k views

How do I run a .sh or .command file in Terminal

I've always wanted to be able to run a script I've downloaded online directly from the Finder but just double clicking the file does not work.
71
votes
5answers
48k views

Update bash to version 4.0 on OSX

Is it possible to actually update bash to version 4.0 in OSX Yosemite? echo $BASH_VERSION 3.2.57(1)-release This article and this thread refer to the same question, but they install a new shell side-...
62
votes
7answers
313k views

How do I set environment variables on OS X?

I have always difficulties setting the Environment variables in OS X like JAVA_HOME, M2_HOME or PATH. How to set these on OS X Mavericks? I did some research but the answers I've found didn't really ...
60
votes
14answers
45k views

How to get a notification when my commands are done

I'm running a series of commands on the command line that takes approximately twenty minutes to complete. I'd like to see some sort of notification on my Mac when these are finished so I don't need ...
58
votes
5answers
29k views

Are Macs vulnerable to the Bash shellshock bug?

Red Hat recently announced a major security-related bug in the Bash shell. Some are calling it the "shellshock" bug. Since OS X is built off of Unix, is it vulnerable to attacks that exploit this bug? ...
54
votes
2answers
60k views

Run AppleScript from bash script

If I wanted to run an AppleScript from within a bash script I could call a file with the list of commands that I require to execute. #!/bin/bash {some commands} osascript file.scpt {other commands} ...
46
votes
5answers
61k views

How to get the fully resolved path of a symbolic link in Terminal?

I have a tangled mess of python installations on my laptop. I was looking at the executables in /usr/local/bin and they are all symbolic links to ../../../Library...... There's some weird behavior ...
43
votes
3answers
4k views

bash vs. zsh: What are the practical differences?

With the news that Catalina will default to zsh instead of bash, I'm finding lots of results telling me about the switch, and that it may cause problems with shell scripts, but I'm not familiar enough ...
39
votes
5answers
6k views

.git-completion.bash producing error on macOS Sierra 10.12.6

I've followed the process for git-completion as per the description provided at https://medium.com/@farooqyousuf/autocomplete-git-commands-and-branch-names-in-terminal-on-mac-os-x-4e0beac0388a: The ...
38
votes
5answers
16k views

Tab completion for hosts defined in ~/.ssh/config doesn't work anymore on Yosemite

I'm trying to create my ~/.ssh/config file for simplify my work life on the server connection. In Mavericks all worked properly and with the tab I was be able to autocomplete the hostname with file ...
36
votes
3answers
25k views

How do I reset the scrollback in the terminal via a shell command?

When using Terminal.app, you can clear the screen by using the shell builtin clear or by pressing ^+L (Control-L). However, all this does is push the current screen content back one screen height ...
35
votes
6answers
61k views

How to set system-wide environment variables on OS X Mavericks

We used to use /etc/environment to set system-wide environment variables on Mountain Lion. However, it seems this file is no longer read. Ideally the solution should apply to all users, and we need ...
33
votes
1answer
70k views

How to remove an environment variable on OSX using bash

I'm running under Snow Leopard 10.6.8 and I recently added an environment variable which it seems to be messing my bash terminal (I guess). What I did is add the variable DYLD_LIBRARY_PATH=/Library/...
32
votes
8answers
24k views

SRM gone in macOS Sierra (10.12)

I've just updated to macOS 10.12 and when I try to execute srm in Terminal, it says -bash: srm: command not found. Is srm removed? How to fix this?
28
votes
2answers
29k views

How do I edit current shell command in VI

I have seen in blogs on Linux machines you can edit the current bash shell command in VI (or whatever the EDITOR is set to) by pressing ctrl-x,ctrl-e. This doesn't seem to work on 10.8. Any ideas on ...
27
votes
5answers
5k views

Did `man ls > temp.txt`. Output textfile is corrupted

When I execute man ls > temp.txt the output text file is corrupted. By corrupted I mean that first and last letters in some words are overly repeated. Several first lines in temp.txt: LS(1) ...
27
votes
6answers
94k views

How to add MySQL to $PATH variable to resolve “mysql: command not found”?

I installed MySQL on my Mac, and now I would like to add it to my $PATH variable. I want to be able to type mysql anywhere. I tried adding the following to my .profile file: export PATH=${PATH}/usr/...
27
votes
7answers
100k views

Using terminal to get current fan speed?

I would like to view the current fan speeds of my MacBook and iMac using terminal. I've found that running spindump then cat /tmp/spindump.txt | grep "Fan speed" will show it, but that's very slow and ...
26
votes
3answers
13k views

How do I make find fail if -exec fails?

When I run this command in the shell (in a non-empty directory): find . -exec invalid_command_here {} \; I get this: find: invalid_command_here: No such file or directory find: invalid_command_here:...
26
votes
6answers
25k views

Why bash history on my mac won't save?

I have always used bash for work, and never had problems with it. Now, it does not save any command in history again. If I open a window terminal, try some commands, it acts like everything has ...
24
votes
3answers
136k views

How to create ~/.bash_profile and ~/.profile

So, I don't have .bash_profile neither .profile in my home folder. How do I create them? After that, what should I do so every time I open the terminal these files get read?
23
votes
1answer
24k views

Using bash/terminal to get number of battery recharge cycles

I would like to get the number of recharge cycles using bash (terminal commands). I understand the following command will display all of the battery data, but I want the cycle count on its own ioreg -...
22
votes
3answers
9k views

Can't increase Mac OSX bash shell history length

I set ~/.bash_profile some time ago to have more than 500 lines length but seems system can't catch this. Do you know why? > nano -w ~/.bash_profile export CLICOLOR=1 export LSCOLORS=...
21
votes
2answers
78k views

Why must I source .bashrc every time I open terminal for aliases to work? [duplicate]

I added this line into my ~/.bashrc file. alias myserver='ssh davidfaux@davidfaux.com' However, when I open terminal and run myserver, terminal complains that -bash: myserver: command not found ...
21
votes
2answers
12k views

Terminal - how to restart session after inadvertently exiting?

Sometimes I inadvertently exit from a Terminal session (usually because I think I'm connected to a remote system, when I'm not), so I get to this point: How I can I restart the session at this point ?...
21
votes
1answer
9k views

How to install imgcat on iTerm2?

Question What do I do with the script? Please explain in plain English in step-by-step fashion. Background I saw that you can display images inline in iTerm2 But when I clicked on the link to ...
21
votes
3answers
11k views

Is it possible to have bash escape spaces in pwd?

I'd like to copy the current directory to the clipboard, something like: pwd | pbcopy. However, pwd does not escape the space, so something in "Application Support", for example, doesn't copy ...
20
votes
2answers
6k views

cd to a directory by typing its name?

For example if a directory 'blob' exists and I just type 'blob[return]' then the system cds into the blob directory for me. In Linux (Ubuntu) I can add shopt -s autocd to my .bashrc file, but on OS X ...
20
votes
3answers
39k views

iTerm colors for Prompt, Command, and Output

Right now my iTerm2 looks like this... Everything is the same color and is hard to read. Can I make any of the Prompt, Command, and Output different colors like this?
19
votes
2answers
15k views

How can I have my shell always start in a certain directory that is not my home directory

I've tried putting cd /Users/my_name/my_directory/structure in both .bashrc and .bash_login but neither works, i.e. when I open a new terminal window I am in my home (/Users/my_name/) directory. No ...
19
votes
3answers
20k views

OS X - Create a personal bin directory (~/bin) and run scripts without specifying their full path

So, what I am trying to do is to create a personal bin directory at my home folder. I created the following folder: /Users/thi/bin I put my scripts in this folder, but if I type in the Terminal: ...
19
votes
6answers
7k views

Slow Terminal on Sierra

The Terminal app is slow at reacting to input, lag is very noticeable when I press and hold Enter. When I type bash to create a sub-shell it becomes much faster. I believe this behavior started when ...
19
votes
2answers
7k views

What does update_terminal_cwd do in the terminal of OS X

I am puzzled by it for quite some while now. In $PROMPT_COMMAND of the bash in OS X, there is a command called update_terminal_cwd. I am sure it's not a bash built in, and most likely only exists in ...
18
votes
4answers
16k views

My Automator Workflow fails because it fails to find the git command within the 'Run Shell Script' command? Need help

I have an Automator workflow and one of the actions is to clone a repository. Here's the code for the 'Run Shell Script' action. The command is run within the Bash shell /bin/bash if that matters: ...
18
votes
2answers
10k views

How to use bash as default shell

I am running El Capitan 10.11.3 with bash version 3.x so I decided to update bash via: brew install bash Brew places the new bash under /usr/local/Cellar/bash: brew info bash bash: stable 4.3.42 (...
18
votes
3answers
16k views

How to enter special characters so that Bash/Terminal understands them?

Let's say a folder has a file called Näyttökuva.png (for those who are interested, it is ”screenshot” in Finnish). This is what happens: $ ls Näyttökuva.png $ ls N* Näyttökuva.png $ ls Nä* ls: Nä*: ...
18
votes
1answer
4k views

globstar: invalid shell option name on macOS even with bash 4.X

The new globstar option requires bash 4. So.. Which bash are we on? $bash --version GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0) Copyright (C) 2016 Free Software Foundation, Inc. ...
18
votes
1answer
19k views

Bash or Zsh, what's the difference, why use one or the other? [duplicate]

So, the question pretty much says it all. I'm on Snow Leopard, and I do a lot of web development, particularly in Rails 3 which makes heavy use of the console. I've seen some notable bloggers etc. ...
17
votes
2answers
4k views

Why is there a left bracket before my bash prompt?

I've notice that after I execute commands, a left bracket character will appear before the previous line. It seems to be partially dependent on what's in $PS1. I've tried unsetting $PROMPT_COMMAND and ...
17
votes
8answers
21k views

sourcing bash profile for root users

Apologies in advance if this question is going to annoy the hell out of everyone as I appreciate, it's been asked in various ways many times before. Please be assured, I have read the archives and ...
17
votes
4answers
12k views

Change file association in terminal?

Is there a method for associating file types with applications via terminal? I thought ~/Library/Preferences/com.apple.launchservices.plist might do it, and I also have seen: Why is a command line ...