简体   繁体   English

如何设置别名以在 Bash 中打开文件

[英]How to set an alias to open a file in Bash

I am trying to set an alias to open an Excel file from a directory on Windows 7. Each time I use the alias it just opens a Windows Explorer window in the root directory. I am trying to set an alias to open an Excel file from a directory on Windows 7. Each time I use the alias it just opens a Windows Explorer window in the root directory.

I am entering:我正在输入:

alias openExcel="explorer /z/Company/AP/PR/thisExcelFile.xlsx"

I have also tried:我也试过:

alias pr="cd /z/Company/AP/PR/"

Then:然后:

alias openExcel="explorer thisExcelFile.xlsx"

Running these commands manually opens the Excel file.手动运行这些命令会打开 Excel 文件。 But using the commands through an alias just opens Windows Explorer in the root directory.但是通过别名使用命令只会在根目录中打开 Windows Explorer。

I have also tried combining the bottom two commands in a function but that didn't work either.我还尝试在 function 中组合底部的两个命令,但这也不起作用。

Can alias' not be used to open files like this?不能使用别名'打开这样的文件吗? Is there some exception to how an alias works when you use the 'explorer' command on Windows?当您在 Windows 上使用“explorer”命令时,别名的工作方式是否有一些例外?

Your commands are fine - you're just running the wrong application.您的命令很好 - 您只是运行了错误的应用程序。

The first part is the command/executable, and the second is the argument.第一部分是命令/可执行文件,第二部分是参数。 You just need to open the file with Excel.您只需要使用 Excel 打开文件。

// This runs "Windows Explorer", with the parameter "thisExcelFile.xlsx"
explorer thisExcelFile.xlsx

// This runs "Microsoft Excel", with the parameter "thisExcelFile.xlsx"
excel thisExcelFile.xlsx

You can do the same with winword myWordDoc.docx , or firefox www.google.com .您可以对winword myWordDoc.docxfirefox www.google.com执行相同操作。

It may also be a good idea to quote the argument, just in case:引用这个论点也可能是一个好主意,以防万一:

excel "thisExcelFile.xlsx"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM