LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 04-25-2011, 01:04 PM   #1
infinitiguy
LQ Newbie
 
Registered: Feb 2008
Posts: 10

Rep: Reputation: 1
issue with multiple variables passed via SSH


Hi guys,
I have 6 machines I'm trying to kick a bunch of commands off on. I need to pass a few variables to them and I only seem to be able to use 1.

script is..
#!/bin/bash
now=`date +%Y%m%d.%H%M%S`
for i in `cat all.txt`; do
ssh $i "mkdir -p $mountdir/test1/bigfiles/big_$i_$now"
done
I've also tried setting $i to another variable and using it, but it gets dropped and only $now is used
+ ssh lintest31601.pre.domain.com 'mkdir -p /mount/testing/test1/bigfiles/big_20110425.135937'

If I remove $now then $i is expanded fine.
+ ssh lintest31601.pre.domain.com 'mkdir -p /mount/testing/test1/bigfiles/big_lintest31601.pre.domain.com'

I'm not sure what could be causing this. I've tried both no quotes and double quotes but to no avail. Anyone have any thoughts?
 
Old 04-25-2011, 01:11 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just a guess: it looks like you missed the braces to embed the variable names:
Code:
big_$i_$now
here the shell tries to substitute a variable called i_ (i underscore, since the underscore is a valid character for variable names), whereas
Code:
big_${i}_${now}
will work with the non-null $i value followed by a literal underscore and by the value of the variable now.
 
Old 04-25-2011, 01:12 PM   #3
infinitiguy
LQ Newbie
 
Registered: Feb 2008
Posts: 10

Original Poster
Rep: Reputation: 1
all set...

stupid quotes.

workingdir="$i"_"$now"


I had been setting $i_$now which the script was reading it as variable1=$i_ and variable2=$now and since the first variable before the "_" was always wrong, therefore null, and appeared dropped.

Syntax will drive me mad someday...
 
Old 04-25-2011, 01:13 PM   #4
infinitiguy
LQ Newbie
 
Registered: Feb 2008
Posts: 10

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by colucix View Post
Just a guess: it looks like you missed the braces to embed the variable names:
Code:
big_$i_$now
here the shell tries to substitute a variable called i_ (i underscore, since the underscore is a valid character for variable names), whereas
Code:
big_${i}_${now}
will work with the non-null $i value followed by a literal underscore and by the value of the variable now.
It's probably good scripting practice to always encase variable names in {}. I think today is going to teach me to start doing that
 
  


Reply



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
page name based on variables passed to it on PHP mohtasham1983 Programming 7 08-09-2007 12:13 PM
PHP: session variables not being passed properly Robhogg Programming 4 07-28-2007 07:38 PM
awk: /matching/ variables passed with -v aunquarra Linux - General 2 02-17-2005 06:47 PM
What are the names of the variables passed to konqueror's email client? BluePyre Linux - Software 0 07-04-2004 11:33 AM
php variables not being passed on tpat Linux - Software 1 01-11-2003 03:11 PM

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

All times are GMT -5. The time now is 10:16 AM.

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