LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-11-2009, 02:27 AM   #1
MaryG
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
Handle $ character in a string


Hi.

I'm new with linux.

I have bash script.
In this script I ask in imput a password and it is like this: wdifg$aa

As you can see there is the $ character in it.

So when I use it I got an error.
I have to replace that password with this: "wdifg\$aa"

How can I do this?

M
 
Old 09-11-2009, 03:14 AM   #2
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
Just incase the string in single quotes:
Code:
# echo '$date'
$date
 
Old 09-11-2009, 05:57 AM   #3
MaryG
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ongte View Post
Just incase the string in single quotes:
Code:
# echo '$date'
$date
Code:
#/bin/bash

read -ep pwd_user

aa=$pwd_user

echo $aa
If I execute this echo command doesn't show anything.
 
Old 09-11-2009, 06:05 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote the variables if you want to display their contents textually.

Code:
echo "$aa"
 
Old 09-11-2009, 06:13 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by MaryG View Post
Code:
#/bin/bash

read -ep pwd_user

aa=$pwd_user

echo $aa
If I execute this echo command doesn't show anything.
Why did you use the -e option?

Try
Code:
read -p 'Enter password: ' pwd_user
echo "DEBUG: pwd_user: '$pwd_user'"
or
Code:
read -p 'Enter password: '
pwd_user="$REPLY'
echo "DEBUG: pwd_user: '$pwd_user'"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Test for last character in string cgraham1 Programming 14 06-11-2009 01:25 PM
Perl File handling issue how to handle ucs 16 character set alix123 Programming 1 10-27-2008 06:51 AM
c++ - How to handle user specified string formatting? BrianK Programming 5 02-27-2008 08:14 AM
unzip seems failing to correctly handle chinese character haodongdong Linux - Software 3 04-23-2005 03:14 AM
Handle escape characters in a string Helene Programming 7 05-01-2004 11:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration