1

I am tryin to insert 3 variables to build a path, but unable to get it .

I am trying the below

log_path="/vol02/logs/$dname/logs/103602_$msname/${msname}_start.log"

dname=cfp
msname=cfp003

i get the below output.

_start.logs/cfp/logs/103602_cfp003

I need

/vol02/logs/cfp/logs/103602_cfp003/cfp003_start.log
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • Place the `dname` and `msname` declarations before the `log_path` declaration, or use single quotes for the `log_path` declaration. – muru Apr 22 '15 at 18:26
  • yes the declarations are before the log_path declaration , and i have used ' quotes instead of , it gives me the output.. /vol02/logs/$dname/logs/103602_$msname/${msname}_start.log doesnt give the variable values – zuhair khan Apr 22 '15 at 18:28

1 Answers1

1

Try this:

dname=cfp
msname=cfp003
log_path="/vol02/logs/${dname}/logs/103602_${msname}/${msname}_start.log"
echo "$log_path"

Output:

/vol02/logs/cfp/logs/103602_cfp003/cfp003_start.log
Cyrus
  • 12,059
  • 3
  • 29
  • 53
  • tried exactly what u said , it still gives the same old output.#!/usr/bin/env bash if [ $((head -1 details.csv)|(cut -d',' -f1,1)) == 'hostname' ]; then #sed -i '1d' details.csv echo 'Hello there....' fi for full_rec in $(cat details.csv) do echo $full_rec hname=`echo $full_rec | cut -d',' -f1,1` dname=`echo $full_rec | cut -d',' -f2,2` msname=`echo $full_rec | cut -d',' -f3,3` log_path="/vol02/logs/${dname}/logs/103602_${msname}/${msname}_start.log" echo "$log_path" echo $hname $dname $msname done output is still _start.logs/cfp/logs/103602_cfp003 – zuhair khan Apr 22 '15 at 18:43
  • Feel free to check and fix your code with http://www.shellcheck.net/ – Cyrus Apr 22 '15 at 19:03
  • still doesnt work, any alternatives? – zuhair khan Apr 22 '15 at 19:35
  • Some ways to debug your script and see content of variables: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Apr 22 '15 at 19:40
  • looks like the problem is in the variable $msname , it extracts the value along with a \r , how do i get rid of \r from the variable ? – zuhair khan Apr 23 '15 at 14:24
  • Try to remove `\r` before it gets into your variable msname: `msname=$(echo $full_rec | cut -d',' -f3,3 | tr -d "\r")` – Cyrus Apr 23 '15 at 15:43