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 .bashrc script.
Here is my .bashrc file
mac $ cat .bashrc
#! /bin/bash
# ~/.bashrc: eyecuted by bash(1) for non-login shells.
# see /usr/share/doc/bash/eyamples/startup-files (in the package bash-doc)
# for eyamples
echo "in .bashrc but claims to be $0"
/usr/bin/id
which id
echo "the path is $(pwd)"
echo "\$PS1 variable is ${PS1}"
echo "\$SHELL variable is ${SHELL}"
echo -e "the path is: \n $PATH"
echo $USER
echo "end of this script."
# how to display an existing function
# declare -f highlightExitCode
highlightExitCode()
{
exit_code=$?
if [ $exit_code -ne 0 ]
then
echo -en " RC=${exit_code} "'\xf0\x9f\x98\xb1\x20'
else
echo -en ""
fi
}mac $
output form running "sudo bash. I have the feeling that bash isn't the running shell. When I have a case statement in .bashrc, I got error messages about the case statement. Why in the world cannot the /usr/bin/id command be found? :...
mac $ sudo bash
in .bashrc but claims to be bash
: No such file or directory
the path is /Users/mac
$PS1 variable is \u$(highlightExitCode) \$
$SHELL variable is /bin/bash
the path is:
/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Developer/Tools:/Users/mac/.nexustools
root
end of this script.
: command not found
: command not found
'ash: /Users/mac/.bashrc: line 18: syntax error near unexpected token `
'ash: /Users/mac/.bashrc: line 18: `highlightExitCode()
bash: highlightExitCode: command not found
root #
I get the same results with "sudo -s":
sudo -s
Password:
in .bashrc but claims to be /bin/bash
: No such file or directory
the path is /Users/mac
$PS1 variable is \u$(highlightExitCode) \$
$SHELL variable is /bin/bash
the path is:
/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Developer/Tools:/Users/mac/.nexustools
root
end of this script.
: command not found
: command not found
'ash: /Users/mac/.bashrc: line 18: syntax error near unexpected token `
'ash: /Users/mac/.bashrc: line 18: `highlightExitCode()
bash: highlightExitCode: command not found
root #
/usr/bin/id<carriage return>
, which doesn't exist. See Why would a correct shell script give a wrapped/truncated/corrupted error message? BTW, TextWrangler can easily convert the file to Unix line endings.