LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-15-2011, 06:26 PM   #1
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
Why can't I put variables in rsync command?


I'm trying to put a variable into the rsync command but I just get some BS error about escaping - whatever that is suppose to mean.

This is my command:


Code:
rsync -rvvuc --exclude '/Output/*' ${OPTARGS} --delete "${SOURCE}scripts/" "${DEST}scripts/"
${OPTARGS} has this value:
--rsh='ssh -p 34'


Wont work. If I type that text directly, then it works. Other then using some if statement to have two different command calls, how can I make this work?
 
Old 02-15-2011, 07:09 PM   #2
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
Ended up rewriting my script in C++, 100 times easier. It was becoming complex and bash syntax can be a real nightmare to work with.
 
Old 02-15-2011, 07:20 PM   #3
Eisennheart
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
Use () instead of {}. Change ${OPTARGS} to $(OPTARGS). So for the whole command use:

rsync -rvvuc --exclude '/Output/*' $(OPTARGS) --delete $(SOURCE)scripts/ $(DEST)scripts/
 
Old 02-15-2011, 10:01 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Quote:
Originally Posted by Eisennheart
Use () instead of {}. Change ${OPTARGS} to $(OPTARGS).
I don't think that would accomplish what Red Squirrel's trying.

Parentheses are command substitution (replacing the contents of the parentheses with the output of a command) and curly braces are parameter substitution (replacing the content of the curly braces with the value of the variable).

It seems clear that Red Squirrel was trying to substitute a variable's value--so the curly braces look like the right decision.

Now, I know there's a C++ substitute, but I'm curious, what was the exact error displayed when trying to use the command as written? "Escaping" a character typically means adding a backslash to one or more characters to prevent the shell from treating it specially (like wildcards for instance). It would also be useful to see the script as a whole, or at least some context around the command.
 
  


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
rsync problems, can you look at my command? - Rsync gurus. Spuddy Linux - Software 4 09-21-2010 10:25 AM
[SOLVED] rsync command windstory Linux - Newbie 2 08-10-2010 01:44 AM
where to put system-wide environment variables otoomet Linux - Software 2 01-07-2008 07:06 AM
Getting o/p of command in variables kushalkoolwal Programming 8 09-25-2005 10:25 AM
Where to put this command? rsamurti Slackware - Installation 4 08-10-2004 12:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:47 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