LoginSignup
8
7

More than 5 years have passed since last update.

macのechoをシェルスクリプト内で使う時に -nオプションを使う方法

Last updated at Posted at 2015-05-29
# シェルスクリプト内で以下のように書くと
echo -n "Are you sure you want to exit the server? [y/n] > "

# 実行時
-n Are you sure you want to exit the server? [y/n] >

(´;ω;`)ウッ…

echoどこにあるの

$ whereis echo
/bin/echo

macの場合だけ/bin/echoを直接指定する

if [ `uname` = "Darwin" ]; then
    /bin/echo -n "Are you sure you want to exit the server? [y/n] > "
  else
    echo -n "Are you sure you want to exit the server? [y/n] > "
fi

/bin/echo を指定すると何故かうまくいく

追記(20150530)

#!/bin/sh

#!/bin/bash

とすることでコードを統一できました。

8
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7