How to call a function in shell Scripting?

后端 未结 7 1044
情话喂你
情话喂你 2020-12-05 05:06

I have a shell script which conditionally calls a function.

For Example:-

if [ \"$choice\" = \"true\" ]
then 
  process_install
elif [ \"$choice\" =          


        
7条回答
  •  再見小時候
    2020-12-05 05:41

    The functions need to be defined before being used. There is no mechanism is sh to pre-declare functions, but a common technique is to do something like:

    main() {
      case "$choice" in
        true)  process_install;;
        false) process_exit;;
      esac
    }
    
    process_install()
    {
      commands...
      commands...
    }
    
    process_exit()
    {
      commands...
      commands...
    }
    
    main()
    

提交回复
热议问题