getopts
is a shell built-in used to parse command line options, while getopt
is its non-built-in counterpart.
Questions tagged [getopts]
118 questions
2
votes
3 answers
How to pass args into scripts?
I am trying to pass arg to this scripts but it does not work anyone knows how fix this ? and I do not want to use args i want to use getopts
For This part
# Get command line parameters
i=
a=
y=
while getopts iay: name
case $name in
…
1
vote
1 answer
parsing getopts
I want to escape the first string SOMETEXT in the getopts args. But I'm only able to do it in the first example.
How can I make it work on the second example?
while getopts p: opt
do
case $opt in
p) result=$OPTARG;;
esac
done
echo "The…

Topas
- 23
1
vote
2 answers
How to input two arguments with getopts?
I am writing a simple bash script. My script installs ppa. The problem is I can't add two arguments. I want to write something simple like this:
./ppa.sh -i ppa:chris-lea/node.js nodejs
I tried this, but doesn't read the second argument…

davidva
- 160
0
votes
2 answers
Use getopt to directly retrieve option value
I am not very experienced with getopt, but in all codes I have seen, it is only being used to reorder the program arguments and then use switch/case to decode which options and arguments are being used, therefore usually requiring to parse (or skip)…

Ferazhu
- 1
0
votes
0 answers
when don't I give the argument to option, option is not working
example code:
function purge() {
delete_dir;
case $purge_arg in
--static)
delete_static_dir;
;;
esac
}
while getopts ":nrp:h" opt; do
case ${opt} in
h ) guide;
;;
n ) new_address;
;;
r )…

rojen
- 184