[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] skip a script based on own filename variable
From: |
Bob Proulx |
Subject: |
Re: [Help-bash] skip a script based on own filename variable |
Date: |
Sat, 20 Apr 2013 21:23:10 -0600 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
adrelanos wrote:
> Chris Down:
> > How about update_command_not_found=70?
>
> I am not eager to rewrite run-parts.
No need for that. Just your own script.
> Perhaps I should rephrase my question.
>
> A script named 70_update_command_not_found is run (by bash, by
> run-parts) and then I wish...
>
> If $MY_OWN_FILENAME is set to zero, exit.
Yes. And Chris' suggestion is a good one. But terse. He did
apologize for being on the phone. Let me paraphrase and modify it to
my own taste. Your code was:
> export 70_update_command_not_found=0
> OWN_FILENAME="$(basename $0)"
> if [ "$OWN_FILENAME" = "0" ];
> true "INFO: Skipping $OWN_FILENAME, because $OWN_FILENAME is set to 0."
> fi
That wouldn't have worked anyway. Because you are trying to
dynamically expand a variable name. You would need eval. Which you
would have figured out if you hadn't hit the variable name starting
with a number first. But $OWN_FILENAME is never going to be "0".
Try this instead.
In caller:
export skip_scripts=":70_update_command_not_found:80_other:"
In your script:
own_filename="$(basename $0)"
case $skip_scripts in
*:$own_filename:*)
: "INFO: Skipping $own_filename, because skip_scripts includes it."
exit 0
;;
esac
: "INFO: running the script past the possible skip step"
There are probably fancier ways to do the check but for debugging
simple is sufficient. Feel free to improve the technique as you see
fit.
Bob
- [Help-bash] skip a script based on own filename variable, adrelanos, 2013/04/20
- Re: [Help-bash] skip a script based on own filename variable, Chris Down, 2013/04/20
- Re: [Help-bash] skip a script based on own filename variable, John Kearney, 2013/04/20
- Re: [Help-bash] skip a script based on own filename variable, John Kearney, 2013/04/21
- Re: [Help-bash] skip a script based on own filename variable, Roman Rakus, 2013/04/21
- Re: [Help-bash] skip a script based on own filename variable, Greg Wooledge, 2013/04/22