how do I treat a special character in my password as not
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
how do I treat a special character in my password as not
i'll start by prefacing my question that it is specific to an OSX version of bash if that makes any difference or not I don't know.
from the command line in an OSX terminal i want to issue a command that requires a sudo password, and lets say my sudo password is "abc&123"
sudo options command
gets me back a line with a little key on the far right side prompting me to enter my password. when i do it doesn't read my full password as abc&123 it splits my password at the & and then it doesn't accept the sudo command.
if i change my password to "abcand123" the sudo command works just fine and the command is executed
question: how can i tell osx to ignore the & character as a "special character" when it's part of my password. i know the easy fix is to just use "abcand123" password, but to help prevent hacking, I'd like to keep my password as complicated as possible and use "special characters" in it.
btw, I have tried to google this but I can't seem to find an answer there.
I think whichever the case may be, szboardstretcher at least has it correct in pointing out that some form of escape needs to be used. Either the backslash, putting the password within quotes, single or double. It depends what the OSX accepts for escape characters, likely the backslash or at least this is what a google search tells me.
I wonder if the command you are running might be a poorly-written shell script which tries to feed your sudo password to some other script without quoting or escaping the password, thereby creating a broken command somewhere in its guts.
For example, the mysql command lets you specify a password on the command line when calling a command. This is not recommended if you are typing commands in a terminal because the password might end up in your .bash_history file, which stores all the commands you enter. However, I recently wrote a script that prompts the user for their database password and then formulates mysql commands using that password. My script is "poorly written" in that it suffers from the very problem I'm trying to describe. I.e., assuming your password is abc&123 then my script constructs a mysql command that looks something like this:
mysql -u root -p abc&123 db_name < db_file.sql
If I enter a password that contains an ampersand, then that ampersand might actually get interpreted by the command line as a BASH operator that says "run this process in the background" or something like that. I'm not sure at all, but the command would be broken into these two commands
mysql -u root -p abc &
123 db_name < db_file.sql
The first command would be executed in the background and would be rejected by mysql as an improperly formulated command. The second would fail with a "123: command not found" or something.
sneakyimp, as far as i can tell, that's exactly what is happening
If you could edit the script you are executing, you could add quotes around the password any time it gets fed into some attempt to formulate a command. That might fix the ampersand problem but would not fix the problem if your password contains a quote in it. You could also change your password
My guess is that you are not actually running BASH on your OSX machine. Also curious why you are editing this file as it doesn't sound like that's where the problem lies.
Some searching yields:
So turns out that on Mac OS X Snow Leopard as well as Mac OS X Lion, the file that's loaded is called .profile, not .bashrc.
What you want to do is create a file in ~/.profile and call it .profile (if it doesn't already exists).
Put whatever information you needed to load with each instance of bash there (Thanks, thepurplepixel).
A couple of side notes:
The period in front of the file marks it as invisible to Finder and the ls command by default. To list invisible files using the ls command from Terminal, use the -a as a parameter as such: ls -a
The ~ symbol stands for /Users/YourUserName where YourUserName is your username's shortname.
Edit: Chris Page notes (correctly) that whatever you place in a .profile file will apply to whatever shell you're using (i.e. zhs, bash, et cetera). If you want the contents to affect only the bash shell, place the contents in a .bash_profile file instead of a .profile file.