Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Bash-how to properly READ and PASTE variables.

Shell Programming and Scripting


Tags
bash, read, replace, string, variables

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-21-2011
arisinhell arisinhell is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 November 2011, 12:59 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Bash-how to properly READ and PASTE variables.

Recently i made a script for a project at molecular dynamics but am stuck at the last step.The thing i want to do is to ask the user to input the number of particles, then replace the bolded numbers at lines 9 and 17..

code


Code:
#!/bin/bash
#read number of particles
echo "insert the number of particles"
read particles
#convert text
#mv coordinates.txt coordinates
#main.in manipulation
#insert number of particles
sed 's/.*input_coord.*/particle 936  #input_coord/g' main.in > main.tmp; mv main.tmp main.in
#remove old coordinates
grep -Ev '#______' main.in  > main.tmp; mv main.tmp main.in
#add new coordinates
sed '/input_coord/ r coordinates' main.in > main.tmp; mv main.tmp main.in
#acf.f manipulation
#add number of particles
sed '3s/.*/      DATA ITM\/1000\/,IM\/936\//' acf.f > acf.tmp; mv acf.tmp acf.f
#xmd
../xmd/src/xmd main.in > timelog.out
#compile acf.f
..
blah
blah


I tried something like this

Code:
read particles
..
sed 's/.*input_coord.*/particle ${particles}  #input_coord/g' main.in >
or
sed 's/.*input_coord.*/particle $particles  #input_coord/g' main.in >

but still nothing..




Thank you in advanceLinux

Last edited by pludi; 11-21-2011 at 03:48 PM..
Sponsored Links
    #2  
Old Unix and Linux 11-21-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 6 December 2016, 4:33 PM EST
Location: Saskatchewan
Posts: 21,661
Thanks: 1,009
Thanked 3,981 Times in 3,698 Posts
Variables will never substitute in single quotes.


Code:
VAR="1234"
echo '${VAR}'
${VAR}
echo "${VAR}"
1234
$

Sponsored Links
    #3  
Old Unix and Linux 11-21-2011
arisinhell arisinhell is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 21 November 2011, 12:59 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
/\

ty i figured it out..

i had to write it like this:


Code:
sed 's/.*input_coord.*/particle '${particles}' #input_coord/g' main.in >

close this thread modsLinux

Last edited by pludi; 11-21-2011 at 03:48 PM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash script to read a hostname and separate into variables glarizza Shell Programming and Scripting 4 06-25-2009 10:36 PM
read file column and paste it in command BearCheese Shell Programming and Scripting 5 04-07-2009 07:46 AM
command paste with variables samos Shell Programming and Scripting 32 03-28-2009 06:49 AM
arrays not printing properly in bash npatwardhan Shell Programming and Scripting 1 11-14-2008 08:30 PM
I can't seem to pass variables properly into a nawk statement DeCoTwc Shell Programming and Scripting 6 03-30-2008 03:07 PM



All times are GMT -4. The time now is 04:34 AM.