POSIX already has a mechanism for dealing with that: PATH. To write a portable bash script, we can therefore not rely on hard-coding the location of the bash program. While on Linux machines it usually is, there are a range of other POSIX machines where bash ships in various locations, such as /usr/xpg/bin/bash or /usr/local/bin/bash. Unfortunately, bash is not always shipped by default, and it is not always available in /bin. The result is that the kernel will run the program /bin/bash to interpret the script. Most commonly, you'll see hash bangs like so: #!/bin/bash (In reality, the kernel will often use the user's default shell to interprete the file, which is very dangerous because it might not be the right interpreter at all or it might be able to parse some of it but with subtle behavioural differences such as is the case between sh and bash). It could be bash, perl, python, sh, or something else. If it doesn't, you're not telling the kernel what it is, and therefore the kernel doesn't know what program to use to interprete it. That means every script that is executable should have a hashbang. Then, the script is passed to the program (as second argument) along with all the arguments you gave the script as subsequent arguments. The hashbang tells the kernel what program to run (in this case the command /usr/bin/env is ran with the argument bash). It should contain a hashbang: #! /usr/bin/env bash For non-binaries, this is done by looking at the first line of the file. When a file is executable, the kernel is responsible for figuring out how to execte it. To make a script executable, give it the necessary permission: chmod +x bar To start an executable (which is any file with executable permission) you just specify it by its path: /foo/bar To run a non-executable bash script, use: bash myscript By using a unique file for each new window it can be used to create many windows at the same time.To run a non-executable sh script, use: sh myscript It does some fancy things like pass your arguments, change the title bar, clear the screen to remove shell startup clutter, remove its file when its done. Then you can run commands in a new window by just adding trun before them, like this: trun tail -f /var/log/system.log Make sure it is executable like this: chmod +x ~/bin/trun I suggest putting it in a directory in your executable path. Set AppleScript's text item delimiters to oldDelims Set theString to the parsedList as string Set AppleScript's text item delimiters to "'\\''" Set the parsedList to every text item of theString Set AppleScript's text item delimiters to "'" Set oldDelims to AppleScript's text item delimiters This simply quotes all occurrences of ' and puts the whole thing between 's Set thePath to (POSIX path of the source_folder as string) Tell application "Finder" to set the source_folder to (folder of the front window) as alias We need to delay, terminal ignores the second do script otherwiseĭo script " cd " & myPath in front window Tell application "System Events" to set isRunning to (exists process "Terminal") If Terminal was not running, one will be opened automatically Tell application "Finder" to set doIt to frontmost Figure out what the path is and quote it (myPath) Figure out if we want to do the cd (doIt) It has all the machinery you need to run commands. Here's my awesome script, it creates a new terminal window if needed and switches to the directory Finder is in if Finder is frontmost.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |