ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
heya all... i need to insert a backslash into an email address variable (to escape the @ symbol) that a user will provide
basically i have a script that asks the user for an email address for input, which i assign to a variable... lets say test@isp.com is what the user gives me... i need to insert a \ before the @ symbol so it reads test\@isp.com
i was figuring that awk would be the best way to do this, but i dont know how to pass a variable (instead of a file) to awk
You need to escape the "\" with another "\" for awk to understand you literally mean "\@" rather than "escape @".
You then need to escape the first escape for the shell script to understand you're passing an escape to awk. (Fun isn't it? )
Note the character before the echo and at end of that line is a back tick (same key as ~) while the character before and after the brackets on that line are single quote (same key as double quote).
In the example I sent you I was assuming passing the email at invocation by typing:
script user@domain
In that the $1 would be the user@domain (first argument passed to script a/k/a first positional parameter).
Instead you are running:
script
In your script you are prompting user then using the "read" directive to assign his response to a variable named "input" so you have to use $input instead of $1.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.