Really dumb qustion about shell scripts

Discussion in 'Apple' started by Király, Jun 8, 2007.

  1. Király

    Király Guest

    I have a Terminal command that I'd like to run when SuperDuper finishes
    its cloning job. I see that SD! has a handy feature to "run shell
    script" at the end of the cloning session.

    Here's my dumb question. Promise you won't laugh.

    How do I turn my Terminal command into a shell script that SuperDuper can
    Király, Jun 8, 2007
    1. Advertisements

  2. Király

    Dave Seaman Guest

    Just enter the command into a text file (say, "mycommand"), and then
    (here's the important part) make the file executable with

    chmod +x mycommand

    and pick some handy place to store it. Then give SD the full pathname of
    the script file that you created, so it will know how to find it.
    Dave Seaman, Jun 8, 2007
    1. Advertisements

  3. Király

    Király Guest

    Well, that was easy enough! Thanks for helping out this clueless
    scripting newbie.
    Király, Jun 9, 2007
  4. Király

    Hans Aberg Guest

    While you are at the console, you might create an empty file using
    touch <filename>
    where <filename> is the file name.

    Then open it in an editor, say TextEdit, using
    open -a TextEdit <filename>

    Hans Aberg
    Hans Aberg, Jun 9, 2007
  5. Király

    Bob Harris Guest

    As has been hinted at, I would strongly suggest adding #!/bin/bash
    on the very first line starting in column 1.


    and then as indicated above, make the script executable using the
    "chmod +x mycommand".

    If your command does NOT use any scripting features specific to
    one of the flavors of shell (sh, ksh, zsh, bash, csh, tcsh, ...)
    then you can get away without the #!/bin/bash (or #!/bin/sh, or
    #!/bin/ksh, or #!/bin/zsh, or #!/bin/csh, or #!/bin/tcsh, ...).

    If you DO use shell specific features, but omit #!/bin/xyz, then
    the highest likely hood is that you script will be invoked by
    /bin/sh, as this is the default shell used by the system(...)
    command, and most likely what SuperDuper! uses (I'm guessing, but
    it is an educated guess).

    Bob Harris
    Bob Harris, Jun 9, 2007
  6. Király

    Király Guest

    Thanks. The command works without the "#!/bin/bash". All the command is
    is a fast-user-switch to the login window, which is invoked with this

    /System/Library/CoreServices/Menu\ Extras/\
    /Resources/CGSession -suspend

    Now when SD finishes running it switches to the login window before it
    sleeps, which was what I wanted.
    Király, Jun 9, 2007
  7. Just to be persnickety: does SD properly interpret a file with just the
    command in it? By this I mean as opposed to being a proper shell
    script file that begins something like


    and so on.
    Carl Witthoft, Jun 9, 2007
  8. Király

    Király Guest

    For me it works fine for me without that extra bit at the beginning.
    Király, Jun 9, 2007
  9. Király

    Dave Seaman Guest

    Dave Seaman, Jun 10, 2007
  10. Király

    Hans Aberg Guest

    Which on Mac OS X is the same as bash (try '/bin/sh --version').

    Hans Aberg
    Hans Aberg, Jun 10, 2007
  11. Király

    Dave Seaman Guest

    Dave Seaman, Jun 10, 2007
  12. Király

    Hans Aberg Guest

    Good point. One will have to watch for this carefully in cross-platform
    development, as bash has a number of extensions that sh does not.

    Hans Aberg
    Hans Aberg, Jun 10, 2007
  13. Shell scripts used to work just fine before the shebang was invented.
    The default shell is /bin/sh.[/QUOTE]

    To be exact, shell scripts work fine so long as they're written in the
    default shell -- FOR THE OS YOU'RE USING. I've run more than one Unix
    box whose default was csh, for example.

    It can be kinda fun playing around w/ pound-splat constructs. I
    forget what I did once but I called some completely different app once
    (i.e. not a unix shell) to do some cool stuff in a script.
    Carl Witthoft, Jun 11, 2007
  14. Király

    Dave Seaman Guest

    Dave Seaman, Jun 12, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.