Results 1 to 3 of 3
  1. #1

    Member Since
    Mar 20, 2009
    noob shell scripting question
    Hi all,

    Just got this book on shell scripting and thought I'd give it a go.

    Here's my script:

    #! /bin/sh
    # titleterm - tells Terminal to change its title to the specified value
    if [ $# != 1 ]; then
      echo "Usage: $0 title" >&2
      exit 1
      echo -n "\033]0;$1\007"
    exit 0
    My problem is with the "-n" option in the second echo command... if I run echo in the command prompt the "-n" option works as advertised, but in the script, -n is interpreted as the string "-n" and not as an option. I'm guessing it's a syntax issue... any suggestions?


  2. #2

    Member Since
    Mar 15, 2007
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    From the man page for echo(1):

    "Some shells may provide a built-in echo command which is similar or identical to this utility. Most notably, the built-in echo in sh(1) does NOT accept the -n option. Consult the builtin(1) manual page."

    You can get the -n option to work if you change to using /bin/bash as the shell rather than /bin/sh (in the first line of your script), or else if you invoke /bin/echo via its explicit path to avoid using the built-in version while continuing to use the standard Bourne shell.

  3. #3

    Member Since
    Mar 20, 2009
    ah I see. Thanks for the pointer!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Bash shell scripting in OS X
    By V6Pony in forum macOS - Development and Darwin
    Replies: 18
    Last Post: 02-24-2016, 11:39 AM
  2. Question about scripting
    By Santos22 in forum macOS - Apps and Games
    Replies: 0
    Last Post: 11-04-2010, 12:29 AM
  3. help with basic shell scripting
    By jrcal in forum macOS - Development and Darwin
    Replies: 0
    Last Post: 06-11-2007, 12:08 PM
  4. Shell scripting
    By badmuthahubbard in forum macOS - Development and Darwin
    Replies: 1
    Last Post: 09-13-2006, 04:16 AM
  5. Samba scripting question
    By nbauer in forum macOS - Operating System
    Replies: 1
    Last Post: 08-06-2005, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts