LoginSignup
9
4

More than 5 years have passed since last update.

シェルスクリプト変数のホームディレクトリ展開

Last updated at Posted at 2015-07-11

wgetでダウンロードシェル書こうとしてホームディレクトリの展開でハマった。
環境はmac。
homebrewでwgetインストール。

var.sh
#!/bin/sh

# substitution
A=~/.get
B="~/.get"
C='~/.get'
D="$HOME/.get"
E='$HOME/.get'

# result
echo "A="$A
echo "B="$B
echo "C="$C
echo "D="$D
echo "E="$E
$ sh var.sh 
A=/Users/user_name/.get
B=~/.get
C=~/.get
D=/Users/user_name/.get
E=$HOME/.get

最初Cパターンやっててハマって、
Bパターン試して、Dパターン試して、Aパターンに落ち着いた感じです。

9
4
0

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
9
4