使用文本和命令中使用? [英] use text and use as command?

查看:78
本文介绍了使用文本和命令中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我whant建立一个脚本来从一个命令文件中提取的话:

i whant to build a script to extract the word from a file in a command:

例如:
在我的文件我把我的用户名,我怎么可以导出的用户名不知道用户名作为我的命令,我这是命令的一部分:暂停这里应该二字出口

for example: in my file i keep my username , how can i export the username without knowing the username as part of my command , which my command is : suspend here should be the word exported?

从我的文件里面有里面的约翰的文字怎么能我告诉命令:暂停该用户名是JOHN

From my file which has the text inside "JOHN" how can i tell the command : suspend that the username is JOHN ?

我怎么能猫/ grep的/ sed的从文件中的文本作为命令的一部分:

how can i cat/grep/sed the text from the file as part of command :

像暂停|猫的文件,我有尝试,但暂停命令不拿用户名,所以应该有不同的东西。

something like suspend |cat file , i have try that but the suspend command does not take the username , so there should be something different .

我IDEEA哪里像这样

my ideea where like this

#!/bin/sh
username=cat my-file;

suspend $username ,

但我从来没有更迭,因为我的$的用户名不是从猫显示,猫是显示它但那一切在做什么。

but i had no succes , because my $username is not display from the cat , the cat is shows it but thats all that is doing.

推荐答案

使用下面的语法

  username=$(cat my-file)

您还可以使用反引号像

  username=`cat my-file`

$( ... 符号是preferable:它可以嵌套,是更具可读性。

but the $(...) notation is preferable: it can be nested and is more readable.

请阅读高级bash脚本编程指南(它会教你很多,即使它可以被批评)

Please read the Advanced Bash Scripting Guide (it will teach you a lot, even if it can be criticized)

您的使用中止是不正确的,我不明白你想用它做什么。什么会中止用户对你意味着什么?也许你想使用指派, pkill的(杀死该用户的所有进程,这是我的感觉是太苛刻了)...?

Your usage of suspend is incorrect, and I don't understand what you want to do with it. What would suspending a user mean to you? Perhaps you want to use pgrep or pkill (to kill all the processes of that user, which I feel is too harsh)...?

这篇关于使用文本和命令中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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