How can I convert this bash function to the fish shell
I'm trying out the fish shell 2.0 to replace bash. I'm trying to convert the following bash function to a fish function, but its giving me hell. I have a several similar functions so if someone could point me in the right direction with an example I would be very grateful
connect() {
if [ "$2" != "" ]
then
ssh -ti ~/.ssh/work/id_rsa user@host$1.domain.com "sudo ssh $2"
fi
if [ "$2" == "" ]
then
ssh -ti ~/.ssh/work/id_rsa user@host$1.domain.com "sudo -i"
fi
}
Tried just replacing $1 and $2 with $argv[1] and $argv[2] but it complains about not being able to locate the end of block. I know its because the scripting synxtax is quite different in fish. I tried starting from a simpler function and had troubles with figuring out how to get it to do one thing if 1 variable is passed, and another thing if 2 variables are passed:
function testvarz
switch "$argv[2]";
case ""
echo "no second variable passed"
case != ""
echo "second variable passed"
end
end
but that doesn't work, if you pass 2 variable it does nothing, if you pass 1 it complains about
I'm trying out the fish shell 2.0 to replace bash. I'm trying to convert the following bash function to a fish function, but its giving me hell. I have a several similar functions so if someone could point me in the right direction with an example I would be very grateful
connect() {
if [ "$2" != "" ]
then
ssh -ti ~/.ssh/work/id_rsa user@host$1.domain.com "sudo ssh $2"
fi
if [ "$2" == "" ]
then
ssh -ti ~/.ssh/work/id_rsa user@host$1.domain.com "sudo -i"
fi
}
Tried just replacing $1 and $2 with $argv[1] and $argv[2] but it complains about not being able to locate the end of block. I know its because the scripting synxtax is quite different in fish. I tried starting from a simpler function and had troubles with figuring out how to get it to do one thing if 1 variable is passed, and another thing if 2 variables are passed:
function testvarz
switch "$argv[2]";
case ""
echo "no second variable passed"
case != ""
echo "second variable passed"
end
end
but that doesn't work, if you pass 2 variable it does nothing, if you pass 1 it complains about
No comments:
Post a Comment