New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

noob shell scripting question

Post Reply New Thread Subscribe

Thread Tools

Member Since: Mar 20, 2009
Posts: 2
mikeb is on a distinguished road

mikeb is offline
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?

QUOTE Thanks

Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
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.
QUOTE Thanks

Member Since: Mar 20, 2009
Posts: 2
mikeb is on a distinguished road

mikeb is offline
ah I see. Thanks for the pointer!
QUOTE Thanks

Post Reply New Thread Subscribe

« 'screen' command in unix | Info.plist to *open* a file »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Noob Question!! Beware! Dj_Noob OS X - Operating System 2 10-21-2008 11:33 PM
Snow Leopard Noob Question borjasanz OS X - Operating System 5 10-14-2008 12:50 PM
noob question (sorry!) skypirate Apple Notebooks 2 07-31-2007 12:33 AM
Noob OS question Joe Blood Switcher Hangout 1 01-23-2006 12:54 PM
Shell script question Niwrad OS X - Development and Darwin 14 06-28-2005 04:58 PM

All times are GMT -4. The time now is 06:32 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?