Topic "Passing variables to the scripts"

Author Message
Anwar BUX

Guest


How can we use variables ie. $1, $2 etc within a script and then pass them at invocation.

For example I create a script which need to Put 3 files to the Open SSH server. I would like to invoke a common script with a stored session and pass the filenames in the command line.
Example:
winscp3 abc@example.com /script=ex.txt file1 file2 file3

Within the script I would use
put $1
put $2
put $3
where $1 = file1 etc.

Any ideas anybody?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
It is not bad idea, however WinSCP currently does not allow it.
But you can easily implement this using .bat file:
Code:
@echo off
rem Do we have some parameters at all?
if "x%1" == "x" goto syntax
rem Delete the old script, if exists
if exist script.txt del script.txt
:next
rem Append "put" command for the file
echo put %1 >> script.txt
rem Delete the first parameter and shift remaning by one to left
shift
rem Are we at the end of parameter list already?
if not "x%1" == "x" goto next
winscp3 abc@example.com /script=script.txt
goto quit
:syntax
echo upload.bat file1 [file2 ...]
:quit

_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License