首页 > 解决方案 > 如何在 .bash_profile macOS 中获取外部文件

问题描述

我试图将我的脚本从 linux 移动到 mac,文件夹 ~/Scripts 与所有其他脚本一起放在家里,
但使用 source in.bash_profile不会调用我的脚本。

.bash_profile 的内容

f [ -f ~/.bashrc ]; then
    . ~/.bashrc
    . ~/Scripts/ipmitool
fi

alias test='echo test from bash_profile'

/Scripts/ipmitool 的内容

#!/bin/bash

if [[ -z $1 ]] ; then
    printf "ipmitool <Host IP> \n\n"
else
    ssh con_1 ipmitool -I lanplus -U * -P * -H  $1 fru print
fi

终端

1232324fa:~ OiO$ ipmitool
-bash: ipmitool: command not found

1232324fa:~ OiO$ bash ~/Scripts/ipmitool
ipmitool <Host IP> 

我需要bash在前面使用才能调用ipmitool,在linux中我只需要输入ipmitool。

我试图按照这个如何在 OSX 的 .bash_profile 中获取外部文件?但没有用。

有人可以帮助这个新手,谢谢。

标签: bashmacosterminalalias

解决方案


看起来您不想获取它。您想要添加~/Scripts到您的路径,以便稍后您可以键入ipmitool而不是~/Scripts/ipmitool执行它。

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

PATH=~/Scripts:$PATH

alias test='echo test from bash_profile'

(确保~/Scripts/ipmitool也是可执行的,通过运行

chmod +x ~/Scripts/ipmitool

)


推荐阅读