如何传递参数为/ bin / bash的? [英] How to pass arguments to /bin/bash?

查看:110
本文介绍了如何传递参数为/ bin / bash的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的终端,我做的
$ myprogram myfile.ext

我希望能够通过命令 /斌/庆典做相同,但它不工作。

I want to be able to do the same via the command /bin/bash, but it is not working.

我试过

$ /bin/bash -c -l myprogram myfile.ext

但它不工作。看来,我的程序启动,但没有我的 file.ext 作为一个选项(如输入文件)

but it is not working. It seems that my program is launched but without my file.ext as an option (as an input file)

有没有人有关于如何做到这一点线索?

Does anyone has a clue on how to do that?

我要启动 myprogram 通过 NSTask 在一个程序我写 OSX ,用可可框架。如果我只是问 NSTask 启动我的程序,似乎有些环境变量失踪。所以,我尝试是推出一个壳,这壳内推出 myprogram

I want to launch myprogram via NSTask in an a program I am writing for OSX, with the cocoa framework. If I simply ask NSTask to launch my program, it seems that some variable environment are missing. So, what I try is to launch a shell and inside this shell to launch myprogram.

推荐答案

完全放弃了 -c 。从手册页:

Drop the -c altogether. From the manpage:

bash [options] [file]
…
Bash  is  an  sh-compatible command language interpreter that executes commands read from the standard input or from a file.

因此​​,你可以通过

Thus, you can execute your program via

bash myprogram myfile.ext

myfile.ext 将是第一个位置参数。

and myfile.ext will be the first positional parameter.

bash -l myprogram myfile.ext

将工作为好,(但bash中是否被援引作为登录shell似乎切了这个问题。)

will work as well, (but whether or not bash is invoked as a login shell seems tangential to this question.)

这篇关于如何传递参数为/ bin / bash的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆