Questions tagged [bash]

The Unix shell formerly used by Terminal in macOS until 10.15

Filter by
Sorted by
Tagged with
2
votes
0answers
1k views

Where is system default environment variable set in MAC OS? [duplicate]

I am using macOS High Sierra V10.13.6. I can set up my custom environment variables in .bash_profile. But where is the system default environment variables are stored in the mac system For Ex: If i ...
3
votes
3answers
1k views

Mac OS X - Bash script if statement based on system status

Creating a bash script and using the if statement, how do I execute a command based on a system status? if a specific system status is enabled do something, else do something different? I give you a ...
0
votes
2answers
216 views

lots of errors after sudo bash in terminal

I want to run lots of terminal commands without having to place sudo in front of every command. I am running in macOS 10.10.5 in terminal. I do sudo bash, but I'm getting lots of errors in my ....
2
votes
2answers
404 views

How to change the password of a local admin user that has never being logged in using a bash script

Every Mac OS X system in my company uses 3 local users accounts. 1st user is a local administrator user, the 2nd user is a local standard user and the 3rd user is a local administrator user. The 3rd ...
1
vote
1answer
56 views

bash command works on Ubuntu but not on macOS

I have this command which works fine on Ubuntu but on macOS I get an error. The command: sudo $(grep -qxF '127.0.0.1 app.local' /etc/hosts || echo '127.0.0.1 app.local' >> /etc/...
6
votes
2answers
720 views

extract the top-level domain and the second-level domain from a URL

I'd like to extra the top-level domain and the second-level domain from a URL like "https://apple.stackexchange.com/questions/ask" Example URL with desired result below. https://apple.stackexchange....
1
vote
1answer
55 views

Tried to use bash arrays but for some reason this fails?

Im trying to make a script that should be executed with crontab, but I'm having difficulties to declare an array an fetch the key and value from that array. (Running MacOS 10.12.6) This is what i'v ...
0
votes
0answers
36 views

Comparing Directory Structures recursively in bash

I'd like to recursively compare two directories in bash using something I can put into an if ![ x=y ] type test. The directories are intended to have a synchronisation between them using rsync which ...
1
vote
1answer
112 views

How to paste files using Applescript (or bash)?

I want to paste a file copied by Finder in the terminal. Sth like pbpaste but for binaries. (pbpaste itself just returns the basename of the copied file.)
1
vote
1answer
51 views

How can I stop AppleScript from converting variables like “\087” into their octal form when passing through bash?

I have a program I'm using to write xml with variables, and it passes through AppleScript and bash to form the final xml. However, one of my variables usually begins with "024", "054", or other three ...
0
votes
1answer
25 views

I have override a file in bin folder and this affect other programs

I was installing phpstorm. It use shortcut to use it in bin files as "ps" to use "ps" in terminal to open phpstorm. I didn't know that a file with that name already existed, and I found that when I ...
2
votes
2answers
116 views

Help to replace a blank space with a backslash and blankspace in a variable in Run Shell Command with Automator

Im creating an automator service that transcodes all the files within a folder to a compressor preset by running the following shell script: VAR="/Applications/Compressor.app/Contents/MacOS/...
9
votes
2answers
1k views

Change the default text editor in Terminal

I just discovered that Control + X + E opens a text editor in the Terminal that allows me to edit the most recent command before executing it again (I think it is actually a bash thing). However, the ...
0
votes
1answer
94 views

How to apply a bash script just to one user account?

Generally speaking I manage my MAC OS X High Sierra and Mojave systems using very basic script(s) that I remotely send and apply to the entire Mac OS X system, that means all these script(s) are ...
4
votes
1answer
111 views

Search folder, copy to new folder and change names of the files!

So I'm trying to recursively search folder, and as you might imagine it will be the "Photos"-folder in MacOS. And in the process, I would like to change the file name, why you might ask? Because ...
0
votes
1answer
61 views

Escape every character in bash

I want to take a string like this: Example string 59^!#&$( And turn it into this: \E\x\a\m\p\l\e\ \s\t\r\i\n\g\ \5\9\^\!\#\&\$\( I've tried: sed -e 's/./\\&/g; 1{$s/^$/""/}; 1!s/^/"/; ...
-1
votes
1answer
277 views

Bash Shell Prompt change color when in root mode

Mac OS X, how do I set the bash shell prompt (PS1) that every time the user type sudo su (root mode) the shell prompt change from the standard color to the red color and of course if the user exit ...
5
votes
0answers
4k views

How to delete pre-installed apps on macOS Catalina [duplicate]

Update: Please check the solution linked by @Phill, verified on 10.15.4 I used csrutil disable to turn off System Integrity Protection and deleted some unused pre-installed apps before macOS 10.14. ...
1
vote
3answers
252 views

Move folders using Terminal by referencing a CSV file

I have a CSV file containing the following two columns: Column A: From Directory (e.g. /Volumes/Backup Plus/Salesforce/Order Test/OR-1000049439). Column B: To Directory (e.g. /Volumes/Backup Plus/...
1
vote
2answers
5k views

Make Homebrew installed Vim override system installed one

I have troubling merging several version of vim on my machine. I have successfully installed vim via Homebrew. Here's the output of running brew info vim: vim: stable 8.1.1550 (bottled), HEAD Vi '...
3
votes
0answers
68 views

How can I detect which button was clicked in the DMG EULA confirmation screen

I'm using the open command to automate (via bash) opening a dmg which has a EULA attached to it. When I run open my_app_distribution.dmg I get a screen that looks like this: The open commands uses ...
1
vote
1answer
257 views

cp command: Overwrite confirmation with file diff

When running cp command to copy files, I would like to be prompted for overwrite confirmation, and, if possible, view the file diff confirming. Is this possible? And if yes, how? Ideal example: $ ...
0
votes
1answer
101 views

What modifies the PATH variable on macOS? [duplicate]

echo $PATH returns a different result than the PATH variable I define in .bashrc. .profile is empty. What else could be modifying the PATHvariable? The directories listed are all things I would have ...
1
vote
1answer
37 views

Get french accent on Linux terminal connected via ssh from MacOS High Sierra

I come on this forum since no answers or suggestions on other forums. I am often connecting from a MacOS High Sierra terminal via SSH to a Debian 8.0. The locales on my MacOS are : LANG= LC_COLLATE="...
2
votes
1answer
618 views

Bash History missing from Terminal

After an OS update, my bash history is suddenly gone - typing "history" at a terminal window (sudo or standard) yields only the commands entered after the upgrade. What could have happened here?
0
votes
1answer
62 views

Prevent Terminal from overwriting preferences on exit

When a user loads my C++ program, I want Terminal to look a certain way. I solved this by wrapping my program in an AppleScript .app which overwrites ~/Library/Preferences/com.apple.Terminal.plist (...
2
votes
1answer
166 views

How to find the PID(s) of a hung app in macOS from the shell (Terminal)?

Within Activity Monitor.app it's easy to visually identify a hung app by seeing its name in red text: How can such hung app statuses be identified from the shell (Terminal.app) and the PID(s) of ...
1
vote
2answers
68 views

Launch of terminal after system login takes around 60 sec, is there a way to speed it up?

Here is my .bash_profile export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "...
3
votes
2answers
473 views

Change output format of “top” command in Mac OS for memory usage?

I am using the top command in Mac OS from this answer to grab memory usage: $ top -l 1 -s 0 | grep PhysMem PhysMem: 5490M used (2569M wired), 11G unused. Can I go from that to possibly printing out ...
169
votes
4answers
56k views

What are the practical differences between Bash and Zsh?

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 ...
3
votes
3answers
670 views

Remove sudoers using script

At the moment I'm working on a solution to prevent all admins users (except one particular) from running sudo. I can add a specific user to sudoers by running: sudo -i echo '$username ALL=(ALL:ALL) ...
1
vote
0answers
45 views

How to associate file extension with executable using bash?

In my bash script setup.sh, how to make macOS associate .foo extension with /usr/local/bin/bar, so that I can click on X.foo in Finder (say) and have macOS perform /usr/local/bin/bar X.foo?
5
votes
3answers
1k views

Can't connect to Internet in bash using Mac OS

My browser works perfectly using the using Internet, however, when I tried to use this command in bash: ping -q -w1 -c1 google.com &>/dev/null && echo online || echo offline It gives ...
0
votes
0answers
132 views

Bash prompt customization not working

I have installed Git Aware Prompt. I have followed the instructions in the project readme file and customised my prompt in ~./bash_profile by adding the following lines: export GITAWAREPROMPT=~/.bash/...
0
votes
1answer
36 views

How to forward delete in Macports?

When using the interactive Macports shell (running port), is there a way to delete characters to the right of the cursor? Normally, you can simply use key the combination Fn + Delete to forward-...
0
votes
1answer
42 views

Mac OS terminal tab separate histories

Terminal gets bash to go through an elaborate dance to keep separate histories for each tab. Normally (for me anyway) after a restart of Mac OS these separate histories are lost and you are left with ...
0
votes
1answer
371 views

Why isn't a binary not being found in my PATH?

I've got a Python project which uses a virtual environment. In my project folder, there is a bin/ folder which contains all the executables needed by the project. To use these, you run source bin/...
0
votes
2answers
2k views

Connect and run commands over SSH using script

I'm using a series of commands for deploying my files to production. This is currently done manually. Is it possible to make these commands into an executable file? So that I don't have to copy paste ...
0
votes
1answer
29 views

Can't store multiple arguments with read -p in macOS terminal using bash

I am trying to store words from an input as parameters with read -p as follows : read -p "Enter your command: " cmd arg1 arg2 echo "$cmd" echo "$arg1" echo "$arg2" With this, $cmd ...
0
votes
1answer
90 views

The command for alias local='…' gets run on terminal open

I have an alias set up in my .bash_profile file: alias local='npm run start-local', and for whatever reason when I open a new terminal session it is trying to run that command npm run start-local ...
0
votes
1answer
33 views

Disable bash command completion (bash v. 5.0.7(1))?

I'm trying to remove all tab completion features from my shell to start over and rebuild it properly. I have homebrew installed and it's running bash v. 5.0.7(1). I had the bash-competion brew ...
0
votes
1answer
9 views

“type” and “which” programs coming up empty for programs on the path

Here is an example of a program that is in the path, find-able by tab / command-completion and accessible but not found by which: kafka- However running which kafka or type kafka comes up empty ...
0
votes
1answer
87 views

Retrieve folder's name for Automator's shell script action

For the sake of concatenating video files, I've assembled bits of code found online into a ffmpeg bash script on Automator. It works. However, I'd like for the output file to be named after the folder ...
3
votes
1answer
3k views

MacBook Pro stuck on GRUB minimal Bash at startup

I had a dual boot Linux Mint 19 and macOS on my MacBookPro11,2. Since the CPU was overheating with Linux, I decided today to delete the Linux partition. Little problem, when I start my MacBook Pro now,...
2
votes
0answers
632 views

Create User via Terminal with Bash in macOS Mojave

In general, you can create a user via Terminal in macOS using Apple's documented method. However, macOS Mojave introduced various security mechanisms that cause scripts to fail when changing user ...
1
vote
1answer
68 views

Running Compiled AppleScript from DMG Doesn't Work

As a follow up for my previous question (Set the Working Folder of .app Created by Apple Script) I have the following problem. I have an AppleScript which is Poor man's Installer: tell me to ...
0
votes
1answer
134 views

Set the Working Folder of `.app` Created by Apple Script

I have a simple Shell File .sh which copies files form the PWD to a destination folder. This is basically Hand Made installer of a program. I want to create an APP from it. The idea is to have the ...
0
votes
0answers
28 views

dyld monitors DYLD_ variables behind the scenes [duplicate]

If I invoke DYLD_X=foo /bin/bash -c 'echo "<$DYLD_X>"' the output is <> while MY_VAR=bar /bin/bash -c 'echo "<$MY_VAR>"' outputs <bar> Switching to Bash 5: DYLD_X=foo /...
1
vote
1answer
180 views

macOS Terminal.app can't split with Command + D

I installed zsh. When I press Command + D in iTerm2, it could split normally. But when I return to using Terminal.app, I use bash or zsh, it can't split with Command + D, it changed like the ...
1
vote
1answer
122 views

bash $PS1 containing an emoj

This question is related to https://apple.stackexchange.com/a/357132/44531 I would like to have a space after the emoj 😱. I've tried in the script below but I'm getting two lines instead of the ...

1
3 4
5
6 7
29