LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2019, 10:36 PM   #1
anon033
Member
 
Registered: Mar 2019
Posts: 188

Rep: Reputation: 13
sed inputs $vat twice


I am writing a script to setup profanity (an xmpp client) for me, it actually doesn't do much but add my account to the rc file (as I don't want to store my account in a public repo). I have this:

Code:
#!/bin/sh

echo "setting up profanity..."

echo "enter your account: "

read account

cat $HOME/.config/profanity/profrc | sed "s/account=/account=$account/" > tmp

echo "profanity setup"
but this inputs the varibale twice, ie

Code:
account=user@host.orguser@host.org
Why is it inputting twice?

Last edited by anon033; 07-01-2019 at 10:59 PM.
 
Old 07-01-2019, 11:44 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Every run of your script inserts the content of $account. Try this:
Code:
sed "s/^account=.*\$/account=$account/"
Note: make sure your $account doesn't contain / \ or & characters.

Last edited by NevemTeve; 07-01-2019 at 11:46 PM.
 
Old 07-02-2019, 06:51 AM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,136
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Code:
echo "setting up profanity..."

echo "enter your account: "

read account
Can be replaced with
Code:
read -p $'setting up profanity...\nenter your account: ' account
 
Old 07-02-2019, 09:23 AM   #4
anon033
Member
 
Registered: Mar 2019
Posts: 188

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by teckk View Post
Code:
echo "setting up profanity..."

echo "enter your account: "

read account
Can be replaced with
Code:
read -p $'setting up profanity...\nenter your account: ' account
read -p *prompt* var

is a bashism and doesn't work for a UNIX shell script.
 
Old 07-02-2019, 09:25 AM   #5
anon033
Member
 
Registered: Mar 2019
Posts: 188

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by NevemTeve View Post
Every run of your script inserts the content of $account. Try this:
Code:
sed "s/^account=.*\$/account=$account/"
Note: make sure your $account doesn't contain / \ or & characters.
That worked! Thank you so much
 
  


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] sed emits a different output for same inputs in different scripts RandomTroll Linux - Software 8 06-27-2019 11:35 PM
[SOLVED] Is there a cli method of running a command twice without having to type it twice? powderburns Linux - Software 4 03-24-2017 09:55 AM
LXer: opentaps Open Source ERP + CRM Targets Europe, Latin America with VAT Support and Translations LXer Syndicated Linux News 0 07-27-2011 10:11 AM
Problem getting Sed to work with special char inputs. shaselai Programming 8 10-23-2009 01:10 PM
[SOLVED] sed inputs from a file not working Fixed_it Programming 9 06-28-2009 02:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:58 PM.

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