Command Expansion Metacharacters
Enclosing command syntax within backquotes, (unshifted tilde, also referred to as backticks) instructs the shell to use the result of the enclosed command(s)... `command syntax`.
This presents a potentially confusing conflict with the SuperCard function merge to work around.
Bash allows an easier to read and less confusing option... '$(command syntax)'.
But, for maximum compatibility, backquotes will be used in wiki examples.
Examples
on mouseup
--Synopsis: set a variable to users home directory path
put "`" into bq
--put a backquote into a variable to escape merge() double quote substitution.
put "_home=[[bq]]cd ~/ ; pwd [[bq]] ;" into cmd
--set the current working directory to users home folder... 'cd ~/'
--Print current working directory... 'pwd'
--Set the variable '_home' to the result
put "echo -n $_home `$_home` `$_home` ; " after cmd
--Echo the contents of '_home' 3 times without appending a linefeed... 'echo -n'
--Note the space between variables in echoed in the output display and...
--the second instance is double quoted in output...
--while the third instance is not
put merge(cmd) into cmd
--Double quote substitution & merge backquote variable into command syntax
get shell(cmd)
--execute command
alert sheet "home path" explain it
--display results
end mouseup
on mouseup
--Synopsis: Set current working directory to users home folder
-- but in a roundabout fashion
-- same as simply doing 'cd ~/'
put "cd / ; " into cmd
--Set up test by changing working directory...
--to boot volume root directory
put "cd <<< `logname` ; " after cmd
--The command 'logname' returns the user log in name.
--The 'here document' redirection operator '<<<' magically allows...
--the change directory command 'cd' to resolve the user name to a path
put "pwd | " after cmd
--To confirm 'cd' worked...
--the print working directory command output is piped to the next command
--via the vertical bar metacharacter '|'
put "perl -pe chomp ;" after cmd
--The Perl function 'chomp' lops off the trailing linefeed
get shell(cmd)
--execute command syntax
alert sheet "my home folder" explain it
--display
end mouseup
Comments (0)
You don't have permission to comment on this page.