首页 > 解决方案 > 波浪号的 Shell 扩展 ~ 在 bash shell 脚本中不起作用

问题描述

这是我的shell脚本

#!/bin/bash

d="${HOME}/image-dir"
# Expanding to /Users/napoleon/image-dir

d1="~/image-dir"
# Expands to ~/image-dir

also in the command line 
echo "~" # output is ~
echo  ~  # output is "/Users/napoleon"

有人可以解释这背后的原因吗?是否按照手册工作

这个问题的目的是了解为什么波浪号不能在双引号“~”内工作。

标签: bashshelltilde-expansion

解决方案


推荐阅读