Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Bash-how to properly READ and PASTE variables.

Shell Programming and Scripting


Tags
bash, read, replace, string, variables

Closed Linux or Unix Question    
 
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 02: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: 22 May 2015, 6:50 PM EDT
Location: Saskatchewan
Posts: 20,650
Thanks: 894
Thanked 3,653 Times in 3,416 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 02:48 PM..
Sponsored Links
Closed Linux or Unix Question

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 09:36 PM
read file column and paste it in command BearCheese Shell Programming and Scripting 5 04-07-2009 06:46 AM
command paste with variables samos Shell Programming and Scripting 32 03-28-2009 05:49 AM
arrays not printing properly in bash npatwardhan Shell Programming and Scripting 1 11-14-2008 07:30 PM
I can't seem to pass variables properly into a nawk statement DeCoTwc Shell Programming and Scripting 6 03-30-2008 02:07 PM



All times are GMT -4. The time now is 12:23 PM.