Expect wigs out when I use the single quote in [exec ls -h | grep '.foo' ]

The name of the pictureThe name of the pictureThe name of the pictureClash 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]"









share|improve this question



















  • 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














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]"









share|improve this question



















  • 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












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]"









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 6 at 21:16

























asked Sep 5 at 11:37









Sometowngeek

1113




1113







  • 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












  • 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







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










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]





share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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]





share|improve this answer






















  • 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














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]





share|improve this answer






















  • 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












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]





share|improve this answer














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]






share|improve this answer














share|improve this answer



share|improve this answer








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 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















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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?