1
I’ve been trying to create a structure if..else
with a parameter passing. See:
Example
$ opt-get -i pacote.tgz
Yes, I’m creating something similar to tool apt-get of the Operating System Debian.
I have made the condition to define and check the parameter:
if [ $1 = "-i" ]; then
Code
#!/bin/sh
#
# (c) 2016 - Diego Henrique Guilherme, <[email protected]>
#
# Programa - opt-get
#
# Aponta para o repositorio
URL=http://mirrors.slackware.com/slackware/slackware-8.1/slackware/tcl/
if [ $1="-i" -a $2="tgz" -o $2="gz" ]
then
wget -c -qO- $URL$2 | sudo tar zxv -C /
else
wget -c -P /tmp/ $URL$2
fi
Commentary
Note that I use the "-a parameter"(And) to include more than one condition within the same function,
On it the commands are executed only if the variable "$1"
be equal to "-i"
And so is the "$2"
this to "tgz" e "gz"
.
In another possibility I use the "-o"(OR) to make the command run if any of the extended conditions "tgz", "gz"
be true.
As you can see I created shell script aesthetically similar to apt-get of SO Debian, having only as main task to download the package and install immediately if the "-i" parameter is passed. If the "-i" parameter is not passed, it simply downloads a package into the folder /tmp
, does not install.
I’ve been changing it for a long time. I don’t know where I could be going wrong.