SuperCard Shell Essentials

 

Variables

Page history last edited by DCS 3 yrs ago

Variables

 

Variables are assigned with the '=' operator.

 

<identifier>=<word> ;

 

Where <identifier> is a word consisting of a leading alpha character or underscore, followed by alphanumeric and underscore characters.

Shell variable identifiers are case sensitive.

 

Variable concatenation.

on mouseup
put "_test='some text' ; echo $_test ; " into cmd
put "_test=$_test', and some more text' ; echo $_test ; " after cmd
put "_test=$_test, and some more text ; echo $_test ; " after cmd
alert sheet "Command result:" explain shell(cmd)
end mouseup

 

Setting a variable to a command result.

A variable may be assigned to the result of a command by command substitution.

Command substitution is introduced by enclosing a command (or string of commands) within backquotes (unshifted tilde).

Bash allows an alternate method... $(<command>)

Note: Backquotes are also used for quote substitution in the SuperCard function 'merge()'

 

on mouseup
put "_test=`dirname ~/` ; " &¬
"_test=$_test/`basename ~/` ; " &¬
"echo $_test ;" into cmd
alert sheet "My Home Folder:" explain shell(cmd)
end mouseup

 

The example below assigns the commandName parameter of the SuperCard function to a shell variable to simplify shell call construction.

 

Attempt to get version info and help text of the named command.
On failure, open console application where error and help text may have been posted.
--
function shellCmdVersionHelp commandName
put "_name=" & commandName & " ; " &¬
"$_name --version  && $_name --help || " into cmd
--
put merge("osascript -e 'tell application `console` to activate' ; ") after cmd
--
return shell(cmd)
end shellCmdVersionHelp

Comments (0)

You don't have permission to comment on this page.