osx - Create Mac terminal script with variable -


i'd create script executes several lines of code, ask user question use variable.

for example, execute in terminal:

git add -a && git commit -m "release 0.0.1." git tag '0.0.1' git push --tags pod trunk push name.podspec 

i'd make 0.0.1 , name variables ask user questions start script off:

what name of pod? version? 

then i'd merge these variables script above. i'm confused "dialect" use (sh, bash, csh, javascript?, etc) , extension should save have double-click it.

how can this?

this should do:

#!/bin/bash read -e -p "what name of pod?" name read -e -p "what version?" ver git add -a && git commit -m "release $ver." git tag "$ver" git push --tags pod trunk push "$name".podspec 

give script suitable name (script or script.sh etc..), assign proper permission:

chmod +x path/to/the/script 

then run terminal:

path/to/the/script 


can make script take name , version arguments too. method combining above is:

#!/bin/bash name="$1";ver="$2" [[ $name == "" ]] && read -e -p "what name of pod?" name [[ $ver == "" ]] && read -e -p "what version?" ver ... 

this has advantage of taking arguments while working first one. can call script arguments:

path/to/the/script podname ver 

and won't ask name , ver, instead take podname name , ver version arguments passed.

if second argument not passed, ask ver.

if none of arguments passed, ask both of them, first code sample.


Comments