I've been trying to create a if..else
structure with a passing parameter. See:
Example
$ opt-get -i pacote.tgz
This, I'm creating something similar to the apt-get tool of the Debian Operating System .
I have made the condition to set and verify 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
Comment
Note that I use the "-a" (E) parameter to include more than one condition within the same function,
In it the commands are executed only if the variable "$1"
is equal to "-i"
And just like "$2"
is to "tgz" e "gz"
.
In another possibility I use "-o" (OU) to make the command run if any of the "tgz", "gz"
extension conditions is true.
As you can see, I created the shell script aesthetically similar to apt-get Debian OS , having only the main task to download the package and immediately if the "-i" parameter is passed. If the "-i" parameter is not passed, it simply drops the package in the /tmp
folder, does not install.
I've been altering for some time .. I do not know where I might be going wrong.