Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash_profile多行别名_Bash_Macos - Fatal编程技术网

bash_profile多行别名

bash_profile多行别名,bash,macos,Bash,Macos,我想运行一个名为“showfiles”的命令,该命令将运行“defaults write com.apple.finder AppleShowAllFiles TRUE”和“killall finder”命令。我该怎么做呢 将这两条语句放在一个文件中,每行一条,并将该文件另存为showfiles 运行chmod 755 showfiles 要执行文件,请运行/showfiles 如果您不想每次都这样做,请将showfiles放入PATH中的任何目录中(您可以通过执行echo$PATH)来查看)

我想运行一个名为“showfiles”的命令,该命令将运行“defaults write com.apple.finder AppleShowAllFiles TRUE”和“killall finder”命令。我该怎么做呢

  • 将这两条语句放在一个文件中,每行一条,并将该文件另存为showfiles
  • 运行
    chmod 755 showfiles
  • 要执行文件,请运行
    /showfiles

  • 如果您不想每次都这样做,请将showfiles放入PATH中的任何目录中(您可以通过执行
    echo$PATH
    )来查看)

    选项1:
    将脚本放在~/bin目录中

    echo "defaults write com.apple.finder AppleShowAllFiles TRUE" > ~/bin/showfiles
    echo "killall Finder" >> ~/bin/showfiles
    chmod +x ~/bin/showfiles
    
    选项2:
    使用和创建别名以将命令连接在一起:

    alias showfiles='defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder'
    

    注意:如果第一个命令成功,这将只运行第二个命令。

    我不确定为什么建议的
    &&
    选项@gahooa不起作用,但还有另一个选项:创建shell函数:

    showfiles() {
        defaults write com.apple.finder AppleShowAllFiles TRUE
        killall Finder
    }
    

    我尝试了选项2,但OS X不喜欢“&&”,我真的不想创建脚本,所以有没有其他方法来创建别名??如果有必要的话,我会创建一个脚本,但是…选项2对我有效,我再次尝试了它,在showfiles=和第一个之间有一个空格。谢谢这太棒了!它本质上允许您创建多行别名(而不仅仅是多命令),从而使读取它们更加清晰。谢谢