LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-17-2004, 04:01 PM   #1
rabbate
LQ Newbie
 
Registered: Feb 2004
Posts: 18

Rep: Reputation: 0
how to escape variable in bash???


Hi. I want to be able to see if bash can escape a variable. The
variable will be *dynammically generated* so I can't just manually put
in slashes. It will be running mysql command and capturing the
output. Example Like this:


#!/bin/bash
VAR = `mysql -u "user" -B -N -e "SELECT auth FROM table WHERE user='xxxx' " db --password="password"`;

echo $VAR; # need it to be escape the "."and "@"

can this be done in bash????
 
Old 03-17-2004, 08:30 PM   #2
cyberfunk
LQ Newbie
 
Registered: Oct 2003
Posts: 14

Rep: Reputation: 0
Can you post the output of the above command, I dont understand what you are trying to achieve.

Cheers

Cyber
 
Old 03-17-2004, 08:49 PM   #3
rabbate
LQ Newbie
 
Registered: Feb 2004
Posts: 18

Original Poster
Rep: Reputation: 0
I am trying to use that returned data and filter it through procmail. Procmail requires data with periods, and @ signs to be escaped. Example of output is from the above query via bash:

@ymdomain.com|info@mysite.com|customersupport@nospam.com|orders@yahoo.net|billing@youcare.net

I want to be able manipulate that data using bash and plug into procmail to filter it as either authorized emails or blocked emails....
 
Old 03-17-2004, 09:02 PM   #4
green_dragon37
Member
 
Registered: Oct 2002
Location: Lower Alabama
Distribution: Slackware, OpenBSD 3.9
Posts: 344

Rep: Reputation: 31
Use sed to replace the '@'s with '/@'s and the '.'s with '/.'s, like so:

var = `echo $var | sed s/@/\\/@/g | sed s/\\./\\/\\./g`

Ian
 
Old 03-17-2004, 09:04 PM   #5
rabbate
LQ Newbie
 
Registered: Feb 2004
Posts: 18

Original Poster
Rep: Reputation: 0
Of course!!! I totally forgot about sed! I use it for other things, but forgot about the application here. Thanks!!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
escape string in bash script so it can be used in command line BuckRogers01 Linux - Software 15 08-12-2010 10:38 AM
bash - escape char problem ddaas Programming 9 11-11-2005 07:08 AM
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 05:38 PM
Variable with bash pinkysioux Programming 6 04-15-2004 09:46 PM
BASH variable export Barbarian Programming 2 11-27-2001 09:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:31 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