"perl -e 'my (undef, undef, undef, $d, $m, $y) = localtime You could write the command to a file and then execute the file like this: There are a variety of ways to pass commands to your shell of choice. Include the shell you want to use explicitly in the command. How do I run my command with a shell other than sh? Second, it matches shell escape mechanisms in other languages, such as Perl. If do shell script used your default shell or PATH, your script would probably break if you gave it to someone else. (This answer glosses over a few details - see Gory Details if you care.) Why doesn’t do shell script work exactly like Terminal?įor two reasons: first, it helps guarantee that scripts will run on different systems without modification. To find the full path in Terminal, say which command-name, for example, which ifconfig to see the list of places do shell script will search, say do shell script "echo $PATH". Use the full path to the command, for example, /sbin/ifconfig instead of just ifconfig. For security and portability reasons, do shell script ignores the configuration files that an interactive shell would read, so you don’t get the customizations you would have in Terminal. Second, when you use just a command name instead of a complete path, the shell uses a list of directories (known as your PATH) to try and find the complete path to the command. You can start sh by typing /bin/sh type exit to get back to your normal shell. If you write your do shell script scripts in Terminal first, always use sh. (To find out what your default shell is, say echo $SHELL in Terminal.) While some commands are the same between shells, others are not, and you may have used one of them. First, do shell script always uses /bin/sh to interpret your command, not your default shell, which Terminal uses. My command works fine in Terminal, but when I try to use it in do shell script, I get an error about “command not found.” What’s going on? In general, you should quote any variables using quoted form of see Dealing with Text for details. Do shell script "echo " & input & " | tr a-z A-Z"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |