Awk syntax error when command is executed through a shell script however the command works fine when executed from Linux bash shellAutomatic exit from bash shell script on errorHow to specify the private SSH-key to use when executing shell command on Git?How to execute mongo commands through shell scripts?How do I run a shell script without using “sh” or “bash” commands?Bash script to execute command on all files in a directorySyntax error in shell script with process substitutionshell commands won't run in bash scriptUnix command to fetch n lines after the grep result in bash is not working when used in conjunction with awkusing sed to set a variable works on command line, but not bash scriptCannot pinpoint my errors in Zkill script

Cannot update a field to a Lookup, MasterDetail, or Hierarchy from something else (44:13)

Did Stalin kill all Soviet officers involved in the Winter War?

Misaligned Columns

Go function to test whether a file exists

I had an c.p.a file late returns, stating i would get money. but i.r.s. says they were filed too late

Show that there are infinitely more problems than we will ever be able to compute

Old story where computer expert digitally animates The Lord of the Rings

Should I cheat if the majority does it?

Is my background sufficient to start Quantum Computing

What does "another" mean in this case?

Phrasing "it says" or "it reads"

List of Implementations for common OR problems

Did Snape really give Umbridge a fake Veritaserum potion that Harry later pretended to drink?

What do you call the angle of the direction of an airplane?

What is the meaning of "stock" dilution on the Massive Dev Chart website?

Pandas merge and fillna

In National Velvet why didn't they use a stunt double for Elizabeth Taylor?

Are there advantages in writing by hand over typing out a story?

Can Monks cast spells?

How to travel between two stationary worlds in the least amount of time? (time dilation)

PhD: When to quit and move on?

What instances can be solved today by modern solvers (pure LP)?

What is meaning of 4 letter acronyms in Roman names like Titus Flavius T. f. T. n. Sabinus?

Why would a propellor have blades of different lengths?



Awk syntax error when command is executed through a shell script however the command works fine when executed from Linux bash shell


Automatic exit from bash shell script on errorHow to specify the private SSH-key to use when executing shell command on Git?How to execute mongo commands through shell scripts?How do I run a shell script without using “sh” or “bash” commands?Bash script to execute command on all files in a directorySyntax error in shell script with process substitutionshell commands won't run in bash scriptUnix command to fetch n lines after the grep result in bash is not working when used in conjunction with awkusing sed to set a variable works on command line, but not bash scriptCannot pinpoint my errors in Zkill script






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am running this command



awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)


On bash and the command works however when executed from a shell script it throws the underlying error



Here is the example and you may look at the 'line 23 error'



# sh -x rvarlog_util.sh
+ findout=/tmp/findout
+ '[' -e /tmp/findout ']'
++ du -sm /var/log
++ awk 'print $1+0'
+ cdu=2372
++ awk 'print $1+0'
++ grep total
++ du -m --max-depth=1 -c -m -x /var/log/messages /var/log/messages-20190310 /var/log/messages-20190323-1553338190.gz /var/log/messages-20190324-1553424406.gz /var/log/messages-20190324-1553456095.gz /var/log/messages-20190324-1553456293.gz /var/log/messages-20190324-1553457237.gz /var/log/messages-20190324-1553457268.gz /var/log/maillog-20190324-1553456095.gz /var/log/boot.log /var/log/audit/audit.log /var/log/audit/audit.log-20190311-1552325090.gz /var/log/puppetlabs
+ fusage=2258
rvarlog_util.sh: line 23: syntax error near unexpected token `('
rvarlog_util.sh: line 23: `awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)'









share|improve this question



















  • 2





    Please format your code properly.

    – Paul R
    Mar 25 at 12:13











  • awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

    – rony thomas
    Mar 25 at 12:16











  • See the link in my comment above for details of how to make your code above display correctly.

    – Paul R
    Mar 25 at 12:23











  • Sure, thank you . Let me format.

    – rony thomas
    Mar 25 at 12:25











  • The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

    – Ed Morton
    Mar 25 at 12:38


















0















I am running this command



awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)


On bash and the command works however when executed from a shell script it throws the underlying error



Here is the example and you may look at the 'line 23 error'



# sh -x rvarlog_util.sh
+ findout=/tmp/findout
+ '[' -e /tmp/findout ']'
++ du -sm /var/log
++ awk 'print $1+0'
+ cdu=2372
++ awk 'print $1+0'
++ grep total
++ du -m --max-depth=1 -c -m -x /var/log/messages /var/log/messages-20190310 /var/log/messages-20190323-1553338190.gz /var/log/messages-20190324-1553424406.gz /var/log/messages-20190324-1553456095.gz /var/log/messages-20190324-1553456293.gz /var/log/messages-20190324-1553457237.gz /var/log/messages-20190324-1553457268.gz /var/log/maillog-20190324-1553456095.gz /var/log/boot.log /var/log/audit/audit.log /var/log/audit/audit.log-20190311-1552325090.gz /var/log/puppetlabs
+ fusage=2258
rvarlog_util.sh: line 23: syntax error near unexpected token `('
rvarlog_util.sh: line 23: `awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)'









share|improve this question



















  • 2





    Please format your code properly.

    – Paul R
    Mar 25 at 12:13











  • awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

    – rony thomas
    Mar 25 at 12:16











  • See the link in my comment above for details of how to make your code above display correctly.

    – Paul R
    Mar 25 at 12:23











  • Sure, thank you . Let me format.

    – rony thomas
    Mar 25 at 12:25











  • The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

    – Ed Morton
    Mar 25 at 12:38














0












0








0








I am running this command



awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)


On bash and the command works however when executed from a shell script it throws the underlying error



Here is the example and you may look at the 'line 23 error'



# sh -x rvarlog_util.sh
+ findout=/tmp/findout
+ '[' -e /tmp/findout ']'
++ du -sm /var/log
++ awk 'print $1+0'
+ cdu=2372
++ awk 'print $1+0'
++ grep total
++ du -m --max-depth=1 -c -m -x /var/log/messages /var/log/messages-20190310 /var/log/messages-20190323-1553338190.gz /var/log/messages-20190324-1553424406.gz /var/log/messages-20190324-1553456095.gz /var/log/messages-20190324-1553456293.gz /var/log/messages-20190324-1553457237.gz /var/log/messages-20190324-1553457268.gz /var/log/maillog-20190324-1553456095.gz /var/log/boot.log /var/log/audit/audit.log /var/log/audit/audit.log-20190311-1552325090.gz /var/log/puppetlabs
+ fusage=2258
rvarlog_util.sh: line 23: syntax error near unexpected token `('
rvarlog_util.sh: line 23: `awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)'









share|improve this question
















I am running this command



awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)


On bash and the command works however when executed from a shell script it throws the underlying error



Here is the example and you may look at the 'line 23 error'



# sh -x rvarlog_util.sh
+ findout=/tmp/findout
+ '[' -e /tmp/findout ']'
++ du -sm /var/log
++ awk 'print $1+0'
+ cdu=2372
++ awk 'print $1+0'
++ grep total
++ du -m --max-depth=1 -c -m -x /var/log/messages /var/log/messages-20190310 /var/log/messages-20190323-1553338190.gz /var/log/messages-20190324-1553424406.gz /var/log/messages-20190324-1553456095.gz /var/log/messages-20190324-1553456293.gz /var/log/messages-20190324-1553457237.gz /var/log/messages-20190324-1553457268.gz /var/log/maillog-20190324-1553456095.gz /var/log/boot.log /var/log/audit/audit.log /var/log/audit/audit.log-20190311-1552325090.gz /var/log/puppetlabs
+ fusage=2258
rvarlog_util.sh: line 23: syntax error near unexpected token `('
rvarlog_util.sh: line 23: `awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findo)'






bash shell awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 12:31









Yaron

6,1176 gold badges30 silver badges45 bronze badges




6,1176 gold badges30 silver badges45 bronze badges










asked Mar 25 at 12:10









rony thomasrony thomas

276 bronze badges




276 bronze badges







  • 2





    Please format your code properly.

    – Paul R
    Mar 25 at 12:13











  • awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

    – rony thomas
    Mar 25 at 12:16











  • See the link in my comment above for details of how to make your code above display correctly.

    – Paul R
    Mar 25 at 12:23











  • Sure, thank you . Let me format.

    – rony thomas
    Mar 25 at 12:25











  • The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

    – Ed Morton
    Mar 25 at 12:38













  • 2





    Please format your code properly.

    – Paul R
    Mar 25 at 12:13











  • awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

    – rony thomas
    Mar 25 at 12:16











  • See the link in my comment above for details of how to make your code above display correctly.

    – Paul R
    Mar 25 at 12:23











  • Sure, thank you . Let me format.

    – rony thomas
    Mar 25 at 12:25











  • The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

    – Ed Morton
    Mar 25 at 12:38








2




2





Please format your code properly.

– Paul R
Mar 25 at 12:13





Please format your code properly.

– Paul R
Mar 25 at 12:13













awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

– rony thomas
Mar 25 at 12:16





awk 'print "Removing " ORS $0;system("rm " $0 ORS " if [ $? -eq 0 ]" ORS "then" ORS "echo file " $0 " has been removed." ORS "fi")' <(cat /tmp/findout) is the command. Are you saying I should be formatting line 23 specifically?

– rony thomas
Mar 25 at 12:16













See the link in my comment above for details of how to make your code above display correctly.

– Paul R
Mar 25 at 12:23





See the link in my comment above for details of how to make your code above display correctly.

– Paul R
Mar 25 at 12:23













Sure, thank you . Let me format.

– rony thomas
Mar 25 at 12:25





Sure, thank you . Let me format.

– rony thomas
Mar 25 at 12:25













The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

– Ed Morton
Mar 25 at 12:38






The problem is almost certainly on some earlier line of your shell script that you aren't showing us, e.g. a missing quote. Post a minimal reproducible example shell script that reproduces the error. Using shell to call awk to call system to call shell to call rm is a terrible idea btw - just call rm directly from shell.

– Ed Morton
Mar 25 at 12:38













2 Answers
2






active

oldest

votes


















2














@Ibraheem has the right solution, but so far nobody's spotted the problem. It's that you're using a process substitution (<(cat /tmp/findo)), but running the script with sh rather than bash. Process substitution isn't available in all shells (or even bash when it's invoked as "sh").



There are a couple of ways to fix this, and I'd recommend doing both ('cause they're good ideas on their own):



  • Don't use <(cat somefile), use a plain redirect, like <somefile. The process-substituted cat command is an overly complex, fragile, and inefficient way to read from a file.


  • Give the script a proper shebang line (#!/bin/bash or #!/usr/bin/env bash), make it executable (chmod +x rvarlog_util.sh), and run it directly by entering its path (./rvarlog_util.sh) rather than explicitly specifying a shell (sh or bash). In general, the script should "know" which shell it's written for, and overriding that (by explicitly specifying a shell when you run it) is a bad idea.






share|improve this answer




















  • 1





    Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

    – Shawn
    Mar 25 at 20:07











  • @Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

    – Gordon Davisson
    Mar 26 at 1:02


















1














from your awk command, what I understood that you are trying to remove files who's names found in /tmp/findo file, is that correct? then replace your awk command with below code and see if it works, BUT make sure that the file names in /tmp/findo contain absolute path to the required files you are trying to remove



while read -r files
do
rm "$files"
if [ $? -eq 0 ]
then
"echo $files has been removed."
fi
done < /tmp/findo





share|improve this answer




















  • 1





    I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

    – Gordon Davisson
    Mar 25 at 18:10











  • Or simpler: xargs -d'n' rm -v </tmp/findo

    – Wiimm
    Mar 26 at 12:57











  • @Wiimm this one liner does the job, thank you very much

    – rony thomas
    Mar 26 at 15:50











  • @Ibraheem, Thank you very much .that works!!

    – rony thomas
    Mar 26 at 15:51











  • @ronythomas welcome, you can accept the answer if that is all you needed,

    – Ibraheem
    Mar 26 at 18:37













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337489%2fawk-syntax-error-when-command-is-executed-through-a-shell-script-however-the-com%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














@Ibraheem has the right solution, but so far nobody's spotted the problem. It's that you're using a process substitution (<(cat /tmp/findo)), but running the script with sh rather than bash. Process substitution isn't available in all shells (or even bash when it's invoked as "sh").



There are a couple of ways to fix this, and I'd recommend doing both ('cause they're good ideas on their own):



  • Don't use <(cat somefile), use a plain redirect, like <somefile. The process-substituted cat command is an overly complex, fragile, and inefficient way to read from a file.


  • Give the script a proper shebang line (#!/bin/bash or #!/usr/bin/env bash), make it executable (chmod +x rvarlog_util.sh), and run it directly by entering its path (./rvarlog_util.sh) rather than explicitly specifying a shell (sh or bash). In general, the script should "know" which shell it's written for, and overriding that (by explicitly specifying a shell when you run it) is a bad idea.






share|improve this answer




















  • 1





    Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

    – Shawn
    Mar 25 at 20:07











  • @Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

    – Gordon Davisson
    Mar 26 at 1:02















2














@Ibraheem has the right solution, but so far nobody's spotted the problem. It's that you're using a process substitution (<(cat /tmp/findo)), but running the script with sh rather than bash. Process substitution isn't available in all shells (or even bash when it's invoked as "sh").



There are a couple of ways to fix this, and I'd recommend doing both ('cause they're good ideas on their own):



  • Don't use <(cat somefile), use a plain redirect, like <somefile. The process-substituted cat command is an overly complex, fragile, and inefficient way to read from a file.


  • Give the script a proper shebang line (#!/bin/bash or #!/usr/bin/env bash), make it executable (chmod +x rvarlog_util.sh), and run it directly by entering its path (./rvarlog_util.sh) rather than explicitly specifying a shell (sh or bash). In general, the script should "know" which shell it's written for, and overriding that (by explicitly specifying a shell when you run it) is a bad idea.






share|improve this answer




















  • 1





    Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

    – Shawn
    Mar 25 at 20:07











  • @Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

    – Gordon Davisson
    Mar 26 at 1:02













2












2








2







@Ibraheem has the right solution, but so far nobody's spotted the problem. It's that you're using a process substitution (<(cat /tmp/findo)), but running the script with sh rather than bash. Process substitution isn't available in all shells (or even bash when it's invoked as "sh").



There are a couple of ways to fix this, and I'd recommend doing both ('cause they're good ideas on their own):



  • Don't use <(cat somefile), use a plain redirect, like <somefile. The process-substituted cat command is an overly complex, fragile, and inefficient way to read from a file.


  • Give the script a proper shebang line (#!/bin/bash or #!/usr/bin/env bash), make it executable (chmod +x rvarlog_util.sh), and run it directly by entering its path (./rvarlog_util.sh) rather than explicitly specifying a shell (sh or bash). In general, the script should "know" which shell it's written for, and overriding that (by explicitly specifying a shell when you run it) is a bad idea.






share|improve this answer















@Ibraheem has the right solution, but so far nobody's spotted the problem. It's that you're using a process substitution (<(cat /tmp/findo)), but running the script with sh rather than bash. Process substitution isn't available in all shells (or even bash when it's invoked as "sh").



There are a couple of ways to fix this, and I'd recommend doing both ('cause they're good ideas on their own):



  • Don't use <(cat somefile), use a plain redirect, like <somefile. The process-substituted cat command is an overly complex, fragile, and inefficient way to read from a file.


  • Give the script a proper shebang line (#!/bin/bash or #!/usr/bin/env bash), make it executable (chmod +x rvarlog_util.sh), and run it directly by entering its path (./rvarlog_util.sh) rather than explicitly specifying a shell (sh or bash). In general, the script should "know" which shell it's written for, and overriding that (by explicitly specifying a shell when you run it) is a bad idea.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 1:03

























answered Mar 25 at 18:21









Gordon DavissonGordon Davisson

74.2k11 gold badges80 silver badges96 bronze badges




74.2k11 gold badges80 silver badges96 bronze badges







  • 1





    Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

    – Shawn
    Mar 25 at 20:07











  • @Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

    – Gordon Davisson
    Mar 26 at 1:02












  • 1





    Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

    – Shawn
    Mar 25 at 20:07











  • @Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

    – Gordon Davisson
    Mar 26 at 1:02







1




1





Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

– Shawn
Mar 25 at 20:07





Quite a few shells support <(command), actually, not just bash. (dash, used for /bin/sh on Debian, Ubuntu, and many other linux distributions isn't one of them, though.)

– Shawn
Mar 25 at 20:07













@Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

– Gordon Davisson
Mar 26 at 1:02





@Shawn Wow, I had no idea, but at least zsh and ksh 93 both support process substitution. I'll edit my answer to correct this.

– Gordon Davisson
Mar 26 at 1:02













1














from your awk command, what I understood that you are trying to remove files who's names found in /tmp/findo file, is that correct? then replace your awk command with below code and see if it works, BUT make sure that the file names in /tmp/findo contain absolute path to the required files you are trying to remove



while read -r files
do
rm "$files"
if [ $? -eq 0 ]
then
"echo $files has been removed."
fi
done < /tmp/findo





share|improve this answer




















  • 1





    I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

    – Gordon Davisson
    Mar 25 at 18:10











  • Or simpler: xargs -d'n' rm -v </tmp/findo

    – Wiimm
    Mar 26 at 12:57











  • @Wiimm this one liner does the job, thank you very much

    – rony thomas
    Mar 26 at 15:50











  • @Ibraheem, Thank you very much .that works!!

    – rony thomas
    Mar 26 at 15:51











  • @ronythomas welcome, you can accept the answer if that is all you needed,

    – Ibraheem
    Mar 26 at 18:37















1














from your awk command, what I understood that you are trying to remove files who's names found in /tmp/findo file, is that correct? then replace your awk command with below code and see if it works, BUT make sure that the file names in /tmp/findo contain absolute path to the required files you are trying to remove



while read -r files
do
rm "$files"
if [ $? -eq 0 ]
then
"echo $files has been removed."
fi
done < /tmp/findo





share|improve this answer




















  • 1





    I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

    – Gordon Davisson
    Mar 25 at 18:10











  • Or simpler: xargs -d'n' rm -v </tmp/findo

    – Wiimm
    Mar 26 at 12:57











  • @Wiimm this one liner does the job, thank you very much

    – rony thomas
    Mar 26 at 15:50











  • @Ibraheem, Thank you very much .that works!!

    – rony thomas
    Mar 26 at 15:51











  • @ronythomas welcome, you can accept the answer if that is all you needed,

    – Ibraheem
    Mar 26 at 18:37













1












1








1







from your awk command, what I understood that you are trying to remove files who's names found in /tmp/findo file, is that correct? then replace your awk command with below code and see if it works, BUT make sure that the file names in /tmp/findo contain absolute path to the required files you are trying to remove



while read -r files
do
rm "$files"
if [ $? -eq 0 ]
then
"echo $files has been removed."
fi
done < /tmp/findo





share|improve this answer















from your awk command, what I understood that you are trying to remove files who's names found in /tmp/findo file, is that correct? then replace your awk command with below code and see if it works, BUT make sure that the file names in /tmp/findo contain absolute path to the required files you are trying to remove



while read -r files
do
rm "$files"
if [ $? -eq 0 ]
then
"echo $files has been removed."
fi
done < /tmp/findo






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 18:19

























answered Mar 25 at 17:54









IbraheemIbraheem

748 bronze badges




748 bronze badges







  • 1





    I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

    – Gordon Davisson
    Mar 25 at 18:10











  • Or simpler: xargs -d'n' rm -v </tmp/findo

    – Wiimm
    Mar 26 at 12:57











  • @Wiimm this one liner does the job, thank you very much

    – rony thomas
    Mar 26 at 15:50











  • @Ibraheem, Thank you very much .that works!!

    – rony thomas
    Mar 26 at 15:51











  • @ronythomas welcome, you can accept the answer if that is all you needed,

    – Ibraheem
    Mar 26 at 18:37












  • 1





    I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

    – Gordon Davisson
    Mar 25 at 18:10











  • Or simpler: xargs -d'n' rm -v </tmp/findo

    – Wiimm
    Mar 26 at 12:57











  • @Wiimm this one liner does the job, thank you very much

    – rony thomas
    Mar 26 at 15:50











  • @Ibraheem, Thank you very much .that works!!

    – rony thomas
    Mar 26 at 15:51











  • @ronythomas welcome, you can accept the answer if that is all you needed,

    – Ibraheem
    Mar 26 at 18:37







1




1





I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

– Gordon Davisson
Mar 25 at 18:10





I'd recommend double-quoting $files both times it's used (and for the echo command, double-quote the entire string). Also, you can simplify it by testing the result of rm directly: if rm "$files".

– Gordon Davisson
Mar 25 at 18:10













Or simpler: xargs -d'n' rm -v </tmp/findo

– Wiimm
Mar 26 at 12:57





Or simpler: xargs -d'n' rm -v </tmp/findo

– Wiimm
Mar 26 at 12:57













@Wiimm this one liner does the job, thank you very much

– rony thomas
Mar 26 at 15:50





@Wiimm this one liner does the job, thank you very much

– rony thomas
Mar 26 at 15:50













@Ibraheem, Thank you very much .that works!!

– rony thomas
Mar 26 at 15:51





@Ibraheem, Thank you very much .that works!!

– rony thomas
Mar 26 at 15:51













@ronythomas welcome, you can accept the answer if that is all you needed,

– Ibraheem
Mar 26 at 18:37





@ronythomas welcome, you can accept the answer if that is all you needed,

– Ibraheem
Mar 26 at 18:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337489%2fawk-syntax-error-when-command-is-executed-through-a-shell-script-however-the-com%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현