Другим способом может быть создание обращений и передача параметра в исполняемый скрипт.Примером может быть: Сначала создайте файл с именем «script.sh».Затем вставьте в него этот код:
#!/bin/sh
my_function() {
echo "this is my function."
}
my_second_function() {
echo "this is my second function."
}
case "$1" in
'do_my_function')
my_function
;;
'do_my_second_function')
my_second_function
;;
*) #default execute
my_function
esac
После добавления приведенного выше кода выполните следующие команды, чтобы увидеть его в действии:
root@shell:/# chmod +x script.sh #This will make the file executable
root@shell:/# ./script.sh #This will run the script without any parameters, triggering the default action.
this is my function.
root@shell:/# ./script.sh do_my_second_function #Executing the script with parameter
this function is my second one.
root@shell:/#
Чтобы сделать эту работу, как вам нужно, вы простонужно запустить
su username -c '/path/to/script.sh do_my_second_function'
и все должно работать нормально.Надеюсь, это поможет:)