I'm trying to write a function that does this:
$ test-function -u {local-path} {destination}
If the first parameter is -u
, then execute a function that takes the next 2 parameters as the path of the file to upload/copy/rsync and the destination.
$ test-function -d {local-path} {destination}
If the first parameter is not -u
(or it is -d
), then execute a function that takes the next 2 parameters as the path of the file to download/copy/rsync (given that I'm at the current folder) and the destination.
I've found answers that suggest the solution here and here. However, my function in my .bash_profile
returns errors like this:
function test_func {
local a="$1"
local a="$2"
if ( a == "-u" ); then
echo "This means upload"
else
echo "This means download"
fi
}
alias test-function="test_func"
Then:
$ test-function -u
-bash: a: command not found
This means download
$ test-function -d
-bash: a: command not found
This means download
If I change the code to:
if [[a == "-u"]]; then
...
This happens:
$ test-function -u
-bash: [[a: command not found
This means download
If I change the code according to one of the answers I found:
if ((a == "-u")); then
...
This happens:
line 53: syntax error near unexpected token `}'
I guess this error is related to the double ((...))
.
How do you do it?