0

I want to use /bin/bash (possibly /bin/sh) with the option -f passed to, and handled by, the script. Precisely,

while getopts f OPT
do
  case $OPT in
    "f" ) readonly FLG_F="TRUE" 
   esac
done

if [ $FLG_F ]; then
  rm -rf $KIBRARY_DIR
fi

and when these lines are in a file http://hoge.com/hoge.sh,

I can do this, for instance,

wget http://hoge.com/hoge.sh
/bin/bash hoge.sh -f

but not

/bin/bash -f hoge.sh

I know the reason but I want to do like this,

wget -O - http://hoge.com/hoge.sh | /bin/bash

with -f option for hoge.sh not for /bin/bash

Are there any good ways to do this?

/bin/bash <(wget -O - http://hoge.com/hoge.sh) -f

worked. but this is only for bash users, right?

6
  • 1
    BTW, you've got some quoting bugs here -- try running your code through shellcheck.net Commented Jul 26, 2016 at 3:24
  • Ohmy,.... thank you for everything.. Commented Jul 26, 2016 at 3:56
  • Also, -f is not the only way to set FLG_F; the value can be inherited from the environment. Try FLG_F=TRUE bash hoge.sh. You'll want to clear the value of FLG_F at the top of your script before you check for the -f option. Commented Jul 26, 2016 at 12:18
  • Running a shell script directly from a 3rd party is a bad idea; download it, verify that it will do what you expect, then run it. Commented Jul 26, 2016 at 12:21
  • 1
    ...and certainly not over plain http; if you don't use SSL, you don't know it's really coming from where you think it is. It really ain't that hard to set up a mutating inline proxy -- heck, I was doing that as part of an April Fool joke almost 20 years ago. Trusting the people you're downloading code from not to have been hacked isn't wise either -- this is why robust software packaging systems (and DSCMs intended to be securable) have support for OpenPGP signatures. Commented Jul 26, 2016 at 12:22

1 Answer 1

4

Using bash you can do

wget -O - http://hoge.com/hoge.sh | /bin/bash -s -- -f

as with -s commands are read from the standard input. This option allows the positional parameters to be set too. It should work with other POSIX shells too.

Sign up to request clarification or add additional context in comments.

2 Comments

It worked. Thank you very much you also considered POSIX Im taking care of.. appreciate it..
This is a bad idea for different reasons; you don't know what you are getting from hoge.com before you execute it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.