linux 中 in命令,在linux c中使用type -t命令?(Using type -t command in linux c.?)

在linux c中使用type -t命令?(Using type -t command in linux c.?)

我用popen来执行type -t type ,这给了我一个错误信息 - 没有找到。 当我在shell中执行type -t type时,这给我内置 。 为什么这不适用于popen ?

I use popen to execute type -t type , this give me an error message -t not found. When I perform type -t type in the shell this gives me builtin. Why doesn't this work with popen?

原文:https://stackoverflow.com/questions/39632689

更新时间:2020-01-26 06:06

最满意答案

POSIX指定与popen使用的shell是/bin/sh 。 你的交互式shell可能是bash 。 对于sh和bash , type命令的行为是不同的。 sh不支持-t 。

您的系统可能具有/bin/sh符号链接到/bin/dash ,但这只是一个实现细节。

如果您需要bash行为,请显式运行bash :

popen("/bin/bash -c 'type -t type'", "r")

POSIX specifies that the shell used with popen is /bin/sh. Your interactive shell is probably bash. The behaviour of the type command is different for sh and bash. sh does not support -t.

Your system probably has /bin/sh symbolically linked to /bin/dash, but that's just an implementation detail.

If you need bash behaviour, run bash explicitly:

popen("/bin/bash -c 'type -t type'", "r")

2016-09-22

相关问答

您可以使用Linux which命令和C函数popen : char testCmd[100];

char usrCmd[100];

strcpy(testCmd, "which ");

strcpy(usrCmd, "cat hello.txt");

strncat(testCmd, usrCmd, 93);

char path[100];

FILE *p = popen( testCmd , "r");

if(p ) {

while(fgets(path, sizeof(path)

...

#include

#include

#include

#include

int main(int argc, char *argv[])

{

int p1[2], p2[2];

int f1, f2, f3;

if(pipe(p1) == -1) {

exit(1);

}

f1 = fork();

if(f1 < 0)

...

模式[A1][AF][AV]匹配以下文件/目录:AAA,AAV,AFA,AFV,1AA,1AV,... 要匹配目录A1 , AF , AV ,请使用模式A[1FV]或{A1,AF,AV} 。 The pattern [A1][AF][AV] matches the following files/directories: AAA, AAV, AFA, AFV, 1AA, 1AV, … To match the directories A1, AF, AV, use the pattern A[1F

...

在SUSE Linux中,默认情况下不安装lshw,但是hwinfo是。 hwinfo --bios

给我 [...]

Memory Device: #38

Location: "DIMM1"

Manufacturer: "Hyundai"

Serial: "0F3005F1"

Asset Tag: "000109"

Part Number: "HMT125U6BFR8C-H9"

Memory Array: #36

Form Factor: 0x09 (DIMM)

...

$output = exec('grep -i hello test.txt | awk -v OFS=, '{\$1=\$1;print}' > newtest.txt');

应该: $output = exec('awk -v OFS=, \'/hello/i {$1=$1;print}\' test.txt > newtest.txt');

您需要转义引号,否则它们会分隔PHP字符串。 您不需要在PHP中的单引号字符串内转义$ 。 如果你想在一个PHP变量中捕获它,你不应该将awk输出重

...

通常将stdin写为短划线( - )。 甚至man cat提到: 没有FILE,或者当FILE是 - 时,读取标准输入。 而手册页甚至有一个例子说明使用破折号和普通文件名(这与您的原始问题非常接近,但包含答案): cat f - g

Output f's contents, then standard input, then g's contents.

it is common to write stdin as dash (-). even man cat menti

...

是这个吗? NAME

popen, pclose - process I/O

SYNOPSIS

#include

FILE *popen(const char *command, const char *type);

int pclose(FILE *stream);

DESCRIPTION

The popen() function opens a process by creating a

...

POSIX指定与popen使用的shell是/bin/sh 。 你的交互式shell可能是bash 。 对于sh和bash , type命令的行为是不同的。 sh不支持-t 。 您的系统可能具有/bin/sh符号链接到/bin/dash ,但这只是一个实现细节。 如果您需要bash行为,请显式运行bash : popen("/bin/bash -c 'type -t type'", "r")

现场演示 。 POSIX specifies that the shell used with p

...

尝试 find /var/www/html/zip/data/*/*/*/*/* -type f -mtime +90 -printf "%h\n" | sort | uniq

Try find /var/www/html/zip/data/*/*/*/*/* -type f -mtime +90 -printf "%h\n" | sort | uniq

尝试这个: <?php

$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);

var_dump($ret);

var_dump($out);

var_dump($err);

?>

更多信息: http : //us3.php.net/manual/en/function.exec.php 此外,如果您期望exec命令要求您为其他用户提供密码(就像在linux命令行中那样) - 它将无法正常工

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值