LinuxQuestions.org
Visit Jeremy's Blog.
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 01-06-2016, 01:27 AM   #1
cbtshare
Member
 
Registered: Jul 2009
Posts: 623

Rep: Reputation: 42
how to disable escape symbol in variable


Hello All,

I have a script which asks for a password and stored the content in $password=<>, but the password is r;OFTaf#a2Mt9d\1
, how can I store the password and not have the backspace interpreted as an escape .

I've tried ""r;OFTaf#a2Mt9d\1"" and "\'r;OFTaf#a2Mt9d\1
\'" but none works.

I even tried pass=> \Q$password\E

Thank you
 
Old 01-06-2016, 01:52 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,281

Rep: Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858
Surround the string with single quotes. See also http://www.gnu.org/software/bash/man...cape-Character.
 
Old 01-06-2016, 01:57 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,993

Rep: Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096
is it bash or perl or ???
 
Old 01-06-2016, 02:16 AM   #4
cbtshare
Member
 
Registered: Jul 2009
Posts: 623

Original Poster
Rep: Reputation: 42
sorry, this is a perl script.
 
Old 01-06-2016, 02:21 AM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 623

Original Poster
Rep: Reputation: 42
Quote:
Originally Posted by berndbausch View Post
Surround the string with single quotes. See also http://www.gnu.org/software/bash/man...cape-Character.
if I use single quotes then there will be no interpolation

$password=<>;

then i use it to ssh to a remote system...user=> $user pass=> $password
 
Old 01-06-2016, 02:39 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,993

Rep: Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096Reputation: 4096
Code:
#!/usr/bin/perl

$p='r;OFTaf#a2Mt9d\1';
$p2=<>;                              ##  << here perl waits for input

print "---------------------\n";
print $p;
print "\n====================\n";
print $p2;
print "\n";
produced the following result:
Code:
/tmp$ ./t.pl
r;OFTaf#a2Mt9d\1                    << this was the password entered by hand
---------------------
r;OFTaf#a2Mt9d\1
====================
r;OFTaf#a2Mt9d\1

/tmp$
So I do not know what is your problem
 
Old 01-07-2016, 06:31 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,842

Rep: Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472
If you are reading the password from a terminal window/terminal it gets tricky...

You have to do things like turning off all the text handling modes in the kernel (setting the terminal to raw mode), and handling each character in the reading so that the termination of the password can be recognized (usually a newline, but it could be something else).

The reason the backspace is consumed is because the kernel uses it to erase the preceding character. It is also the normal character used to delete characters while entering a password, so it is USUALLY not available as a password character itself (the same can be said of the newline character as that normally indicated "end of password input"). You CAN change the delete function from using the backspace... but then the other character will not be available as part of the password.

It is also very weak security, partly due to the error prone nature of getting it right.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Bash - escape all special characters in variable string? arashi256 Linux - Newbie 10 01-23-2012 09:43 AM
awk not escape my bash variable winggundamth Programming 7 08-10-2011 08:33 AM
Any way to disable the escape sequence with "screen"? slinx Linux - General 2 01-06-2010 09:04 AM
how to escape variable in bash??? rabbate Linux - General 4 03-17-2004 08:04 PM
disable escape def1014 Linux - Security 1 04-16-2002 04:02 PM

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

All times are GMT -5. The time now is 03:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration