Expect wigs out when I use the single quote in [exec ls -h | grep '.foo' ]
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am trying to store a list of specific files into a variable in expect.
In my script, I am trying to compile files that have different file extensions, like .foo, .bar.
In this example, I have the following files:
- something.foo
- something_new.foo
- something_different.bar
- this_is_the_wrong_one.sh
To get just .foo files, I tried to run this:
set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]"
send_user "$filesn"
I was expecting to see:
- something
- something_new
However, I ended up getting this error message:
child process exited abnormally
while executing
"exec ls -h | grep -E '.foo' | rev | cut -c5- | rev"
invoked from within
"set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]""
(file "./runthis.sh" line 2)
I know I could use find '*.foo'
, ls -h *.foo
, awk
, etc. I noticed the pattern... with find
, expect wigs out if I use the '
(single quote), so that pretty much eliminates the idea of using find
, awk
, and grep
. If I use ls -h *.foo
and the files don't exist, the script will stop. It is supposed to continue checking and listing other files.
If it finds the files, it will eventually be split into an array using this command:
Update 1:
set split_files "[split $files n]"
grep ls expect tcl
add a comment |Â
up vote
2
down vote
favorite
I am trying to store a list of specific files into a variable in expect.
In my script, I am trying to compile files that have different file extensions, like .foo, .bar.
In this example, I have the following files:
- something.foo
- something_new.foo
- something_different.bar
- this_is_the_wrong_one.sh
To get just .foo files, I tried to run this:
set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]"
send_user "$filesn"
I was expecting to see:
- something
- something_new
However, I ended up getting this error message:
child process exited abnormally
while executing
"exec ls -h | grep -E '.foo' | rev | cut -c5- | rev"
invoked from within
"set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]""
(file "./runthis.sh" line 2)
I know I could use find '*.foo'
, ls -h *.foo
, awk
, etc. I noticed the pattern... with find
, expect wigs out if I use the '
(single quote), so that pretty much eliminates the idea of using find
, awk
, and grep
. If I use ls -h *.foo
and the files don't exist, the script will stop. It is supposed to continue checking and listing other files.
If it finds the files, it will eventually be split into an array using this command:
Update 1:
set split_files "[split $files n]"
grep ls expect tcl
1
You wantset split_files [split $files n]
-- without the$
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.
â glenn jackman
Sep 5 at 19:15
Don't parse the output ofls
â glenn jackman
Sep 5 at 19:16
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to store a list of specific files into a variable in expect.
In my script, I am trying to compile files that have different file extensions, like .foo, .bar.
In this example, I have the following files:
- something.foo
- something_new.foo
- something_different.bar
- this_is_the_wrong_one.sh
To get just .foo files, I tried to run this:
set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]"
send_user "$filesn"
I was expecting to see:
- something
- something_new
However, I ended up getting this error message:
child process exited abnormally
while executing
"exec ls -h | grep -E '.foo' | rev | cut -c5- | rev"
invoked from within
"set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]""
(file "./runthis.sh" line 2)
I know I could use find '*.foo'
, ls -h *.foo
, awk
, etc. I noticed the pattern... with find
, expect wigs out if I use the '
(single quote), so that pretty much eliminates the idea of using find
, awk
, and grep
. If I use ls -h *.foo
and the files don't exist, the script will stop. It is supposed to continue checking and listing other files.
If it finds the files, it will eventually be split into an array using this command:
Update 1:
set split_files "[split $files n]"
grep ls expect tcl
I am trying to store a list of specific files into a variable in expect.
In my script, I am trying to compile files that have different file extensions, like .foo, .bar.
In this example, I have the following files:
- something.foo
- something_new.foo
- something_different.bar
- this_is_the_wrong_one.sh
To get just .foo files, I tried to run this:
set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]"
send_user "$filesn"
I was expecting to see:
- something
- something_new
However, I ended up getting this error message:
child process exited abnormally
while executing
"exec ls -h | grep -E '.foo' | rev | cut -c5- | rev"
invoked from within
"set files "[exec ls -h | grep -E '.foo' | rev | cut -c5- | rev]""
(file "./runthis.sh" line 2)
I know I could use find '*.foo'
, ls -h *.foo
, awk
, etc. I noticed the pattern... with find
, expect wigs out if I use the '
(single quote), so that pretty much eliminates the idea of using find
, awk
, and grep
. If I use ls -h *.foo
and the files don't exist, the script will stop. It is supposed to continue checking and listing other files.
If it finds the files, it will eventually be split into an array using this command:
Update 1:
set split_files "[split $files n]"
grep ls expect tcl
grep ls expect tcl
edited Sep 6 at 21:16
asked Sep 5 at 11:37
Sometowngeek
1113
1113
1
You wantset split_files [split $files n]
-- without the$
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.
â glenn jackman
Sep 5 at 19:15
Don't parse the output ofls
â glenn jackman
Sep 5 at 19:16
add a comment |Â
1
You wantset split_files [split $files n]
-- without the$
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.
â glenn jackman
Sep 5 at 19:15
Don't parse the output ofls
â glenn jackman
Sep 5 at 19:16
1
1
You want
set split_files [split $files n]
-- without the $
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.â glenn jackman
Sep 5 at 19:15
You want
set split_files [split $files n]
-- without the $
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.â glenn jackman
Sep 5 at 19:15
Don't parse the output of
ls
â glenn jackman
Sep 5 at 19:16
Don't parse the output of
ls
â glenn jackman
Sep 5 at 19:16
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
The problem is that single quotes are not special to tcl
, so you are actually running the grep
command with the argument '.foo'
, including the quotes which normally you would expect to be removed by the shell.
This makes the grep
fail to match, so it exits with a non-zero error code, and so the exec
command passes on the error.
The immediate answer is to use tcl
double-quotes (grep -E "\.foo"
) or no quotes (grep -E \.foo
) or brace-quotes (grep -E .foo
). But an alternative is to not resort to shell commands. The equivalent in tcl
might be:
set fullfiles [glob *.foo]
foreach f $fullfiles lappend files [string trimright $f .foo]
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing withls
andgrep
and it turns out that expect probably pukes on the grep part. Hrmm...
â Sometowngeek
Sep 6 at 21:18
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
The problem is that single quotes are not special to tcl
, so you are actually running the grep
command with the argument '.foo'
, including the quotes which normally you would expect to be removed by the shell.
This makes the grep
fail to match, so it exits with a non-zero error code, and so the exec
command passes on the error.
The immediate answer is to use tcl
double-quotes (grep -E "\.foo"
) or no quotes (grep -E \.foo
) or brace-quotes (grep -E .foo
). But an alternative is to not resort to shell commands. The equivalent in tcl
might be:
set fullfiles [glob *.foo]
foreach f $fullfiles lappend files [string trimright $f .foo]
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing withls
andgrep
and it turns out that expect probably pukes on the grep part. Hrmm...
â Sometowngeek
Sep 6 at 21:18
add a comment |Â
up vote
4
down vote
The problem is that single quotes are not special to tcl
, so you are actually running the grep
command with the argument '.foo'
, including the quotes which normally you would expect to be removed by the shell.
This makes the grep
fail to match, so it exits with a non-zero error code, and so the exec
command passes on the error.
The immediate answer is to use tcl
double-quotes (grep -E "\.foo"
) or no quotes (grep -E \.foo
) or brace-quotes (grep -E .foo
). But an alternative is to not resort to shell commands. The equivalent in tcl
might be:
set fullfiles [glob *.foo]
foreach f $fullfiles lappend files [string trimright $f .foo]
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing withls
andgrep
and it turns out that expect probably pukes on the grep part. Hrmm...
â Sometowngeek
Sep 6 at 21:18
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The problem is that single quotes are not special to tcl
, so you are actually running the grep
command with the argument '.foo'
, including the quotes which normally you would expect to be removed by the shell.
This makes the grep
fail to match, so it exits with a non-zero error code, and so the exec
command passes on the error.
The immediate answer is to use tcl
double-quotes (grep -E "\.foo"
) or no quotes (grep -E \.foo
) or brace-quotes (grep -E .foo
). But an alternative is to not resort to shell commands. The equivalent in tcl
might be:
set fullfiles [glob *.foo]
foreach f $fullfiles lappend files [string trimright $f .foo]
The problem is that single quotes are not special to tcl
, so you are actually running the grep
command with the argument '.foo'
, including the quotes which normally you would expect to be removed by the shell.
This makes the grep
fail to match, so it exits with a non-zero error code, and so the exec
command passes on the error.
The immediate answer is to use tcl
double-quotes (grep -E "\.foo"
) or no quotes (grep -E \.foo
) or brace-quotes (grep -E .foo
). But an alternative is to not resort to shell commands. The equivalent in tcl
might be:
set fullfiles [glob *.foo]
foreach f $fullfiles lappend files [string trimright $f .foo]
edited Sep 5 at 17:30
glenn jackman
48.1k365105
48.1k365105
answered Sep 5 at 13:29
meuh
30.2k11752
30.2k11752
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing withls
andgrep
and it turns out that expect probably pukes on the grep part. Hrmm...
â Sometowngeek
Sep 6 at 21:18
add a comment |Â
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing withls
andgrep
and it turns out that expect probably pukes on the grep part. Hrmm...
â Sometowngeek
Sep 6 at 21:18
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing with
ls
and grep
and it turns out that expect probably pukes on the grep part. Hrmm...â Sometowngeek
Sep 6 at 21:18
I tried using glob, but it seems the linux server doesn't support glob. Sadly, I don't have the authorization to install it on the server. I did further testing with
ls
and grep
and it turns out that expect probably pukes on the grep part. Hrmm...â Sometowngeek
Sep 6 at 21:18
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466992%2fexpect-wigs-out-when-i-use-the-single-quote-in-exec-ls-h-grep-foo%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
You want
set split_files [split $files n]
-- without the$
on the variable name, and without the quotes. Also, meuh's answer already gives you a list.â glenn jackman
Sep 5 at 19:15
Don't parse the output of
ls
â glenn jackman
Sep 5 at 19:16