Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this bash syntax mean? (Featuring: case, exec)

Tags:

linux

bash

What is the purpose of this bash script? (It is a portion of a larger script.)

if [ $# -gt 0 ]
then
  case $1 in
  -*) ;;
  *) exec $* ;;
esac
fi

A related question:

https://stackoverflow.com/questions/2046762/problem-with-metamap-inappropriate-ioctl-for-device

like image 765
Rohit Banga Avatar asked Aug 17 '26 14:08

Rohit Banga


2 Answers

In English, line-by-line:

if the number of arguments is greater than 0
then
if the first argument...
  starts with '-', do nothing
  else, "exec" the arguments (run the entire set of arguments as a command replacing this process, not as a child process)
(end of case)
(end of if)
like image 94
Laurence Gonsalves Avatar answered Aug 19 '26 03:08

Laurence Gonsalves


Not knowing any bash scripting I'd say this

  • looks for whether the number of arguments is larger than 0
  • if it is, it looks at the first argument
    • If it starts with - it does nothing
    • Otherwise it executes all arguments as a single command line
like image 22
Joey Avatar answered Aug 19 '26 04:08

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!