LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 07-14-2008, 05:42 PM   #1
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,564
Blog Entries: 1

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
lftp + bash variables


I'd like to create a simple script, something like that:

Code:
vim $1
lftp -c 'open -e "put $1" sycamorex@192.168.1.102:/data/notes/'
But lftp doesn't see $1 as a variable and treats it literally:
Code:
put: /home/xtd8865/notes/autoup/$1: No such file or directory
If I replace 'put $1' with a file name in this directory, everything works.

any hints

thanks
 
Old 07-14-2008, 08:31 PM   #2
pxsnet
LQ Newbie
 
Registered: Mar 2004
Location: CHN
Distribution: gentoo, RHEL
Posts: 16

Rep: Reputation: 0
single quotation marks are used so no var substitution happens.
 
Old 07-15-2008, 04:11 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,564
Blog Entries: 1

Original Poster
Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
I might have not been clear as to what I'd like to do. I do want var substitution to happen.
Instead of the file called $1, I want lftp to substitute the $1 variable and upload the file the file
that was created as the $1 argument of my script.

any ideas?
thanks
 
Old 07-15-2008, 04:44 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,506

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
What pxsnet was trying to explain is that the embedding single quotes around the lftp command - as in your statement - prevent variable substitution. In alternative to the one-line syntax, you can try with a "here document":
Code:
lftp << EOF
open 192.168.1.102
cd /data/notes
put $1
bye
EOF
 
Old 07-16-2008, 05:57 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,564
Blog Entries: 1

Original Poster
Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
thanks, it works fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash: what happens to my variables? elinenbe Programming 5 01-30-2008 02:32 PM
bash variables pfaendtner Linux - Newbie 4 11-23-2004 01:00 PM
variables in bash haddad Linux - General 6 09-22-2004 05:29 PM
Variables in bash tcaptain Programming 1 03-03-2003 02:07 PM
Bash variables pk21 Programming 2 01-09-2003 03:31 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration