I have an Expect program that takes a single command line parameter, which
is a filename (which must exist). The program starts with:
#!/usr/bin/expect --
if {$argc != 1 || ![file exists $argv]} { puts "Error";exit 1 }
{/path/to/file name with spaces}
The curly braces foo up the "file exists" check. I am able to workaround this by adding the following line before the above "if" statement:
set argv [join $argv]
And this seems to be the fix. As far as I can tell, the above line doesn't break anything. In fact, I've used this kludge/hack in the past, so I
didn't have to invent it anew today. But why is it necessary? Isn't it weird that it is necessary?
Hello,
I have an Expect program that takes a single command line parameter, which
is a filename (which must exist). The program starts with:
#!/usr/bin/expect --
if {$argc != 1 || ![file exists $argv]} { puts "Error";exit 1 }
In article <t5otpa$s5p$1@gioia.aioe.org>, <saitology9@gmail.com> wrote:
...
Hello,
Thank you for your response.
However, it does not tell me anything I didn't already know.
if {$argc != 1 || ![file exists $argv]} { puts "Error";exit 1 }
But thank you anyway.
P.S. Yes, it is weird. Why is join needed? I.e., am I correct in
assuming that it only puts the {} in, when there is a space (or some other "weird" character) in the filename?
In article <t5otpa$s5p$1...@gioia.aioe.org>, <saito...@gmail.com> wrote:
...
Hello,
Thank you for your response.
However, it does not tell me anything I didn't already know.
But thank you anyway.
P.S. Yes, it is weird. Why is join needed? I.e., am I correct in
assuming that it only puts the {} in, when there is a space (or some other "weird" character) in the filename?
From: gazelle@shell.xmission.com (Kenny McCormack)
Date: Sat May 14 11:27:23 GMT 2022
Subject: Why do I need to "join" it?
is a filename (which must exist). The program starts with:
#!/usr/bin/expect --
if {$argc != 1 || ![file exists $argv]} { puts "Error";exit 1 }
This works fine as long as the filename is "normal" - i.e., doesn't contain >any spaces (and/or perhaps other weird characters). However, if it has a >space, then the "file exists" check fails, because the actual value of
$argv is something like:
{/path/to/file name with spaces}
I'm confused, when I remove argc!=1 test in the if statement, the file exists part seems to work for file names with or without spaces, as long as spaces are separated by non-space characters. If two or more spaces are next to each other, it will fail (or use the wrong file if there is one where all runs of multiple spaces in the name are replaced by single spaces).
As noted in other replies above it is tacky, but it does work (for files with no runs of multiple spaces in their names)
If you want to handle really weird file names, enclose any odd file name in quotes on the command line:
expect-script "/path/to/file name with spaces"
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 489 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:55:50 |
Calls: | 9,670 |
Calls today: | 1 |
Files: | 13,716 |
Messages: | 6,169,850 |