使用linux我如何将文件的内容作为参数传递给可执行文件? [英] using linux how can I pass the contents of a file as a parameter to an executable?

查看:986
本文介绍了使用linux我如何将文件的内容作为参数传递给可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要使用字符串参数运行./program

let's say I want to run ./program with a string argument

代替打字 每次./program string,我怎么做./program <file>,其中<file>是一个包含字符串的文件?

instead of typing ./program string each time, how can I do ./program <file> where <file> is a file that contains string?

谢谢

推荐答案

这应该可以解决问题:

./program `cat file`

如果要在单个参数中包含整个文件的内容,请添加双引号(在bash中进行了测试.我认为它可能会因外壳而异):

If you want the entire file content in a single argument, add double quotation (tested in bash. I think It may vary shell to shell) :

./program "`cat file`" 

这篇关于使用linux我如何将文件的内容作为参数传递给可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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