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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how do I treat a special character in my password as not
hi guys,
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:
Code:
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
Code:
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
in linux i would simple enter the command texedit .bash from my home directory
if i try open -e .bash from my home directory it says that file does not exist, if i try the same command with .bashrc i get the same answer does not exist.
when i try to ls .* it also does not list a .bash or .bashrc file
where else could my .bash file be located, or what else am i doing wrong?
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:
Quote:
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.
actually that's one reason why (on my linux box at work) i have an alias ll = 'ls -alhf' and then i never type ls i just always type ll so i don't forget all the options...
well creating a .bash_profile or just a .profile in osx, osx does appear to apply the command when opening a new terminal, however i get lots of errors
note, it is a bash shell because the is a .bash_history file and a .bash_sessions directory
can someone reccommend an osx specific forum like linux questions, or is there a osx specific forum here, i haven't found one
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.