登录 立即注册

找到11528个回复

弟妹 15楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)
@无名啊,我是python2 2>file.err 这么测试的,sed我是不太会用
无名啊 14楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

因为机器没网,电脑里没有这个软件。所以就没采用这个。。。

Emm..?不需要额外安装啥软件呀,只是加一行bash代码

然后,我是拿python2.7测试--version输出到错误流的(我还没测试其他机器的2.7是否也这样)

我不熟悉Python 2,我电脑也没装,那就不清楚了

无名啊 13楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

噢,我看漏了这一句

并开启交互式shell

看来,你读了 7 楼的

只是,这nodejs代码里,哪一行是代表连接到了tty吗?(我不熟悉nodejs,但我还是能看得懂很多js的,即使是到ES2022

弟妹 12楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)
@无名啊,我知道7楼这个方案,因为机器没网,电脑里没有这个软件。所以就没采用这个。。。

使用的交互式shell,是不好用的。

然后,我是拿python2.7测试--version输出到错误流的(我还没测试其他机器的2.7是否也这样)
无名啊 11楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

PS: python --version竟然输出到错误流 真离谱

我瞅了瞅,应该是输出至stdout的?

$ python3 --version | sed 's/^/[STDOUT] /'
[STDOUT] Python 3.10.5
无名啊 10楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹,看来,你没看 7 楼

await execRequest('bash',['shopt -s expand_aliases', 'alias python233=python2', 'python233 --version 2>&1'])
弟妹 9楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@无名啊,以Node.js 创建子进程为例

import * as child from 'child_process'

export async function execRequest(cmd: string, commands: string[]) {
    return new Promise((resolve) => {
        let spawnChild = child.spawn(cmd)
        spawnChild.stdout.on('data', ch => {
            console.log(ch.toString().trim())
        })
        spawnChild.stderr.on('data', ch => {
            console.log(ch.toString().trim())
        })

        spawnChild.on('exit', code => {
            console.log(code)
        })

        commands.forEach((command) => {
            spawnChild.stdin.write(`${command}\n`)
        })

        spawnChild.stdin.end('\nexit\n')
    })
}

await execRequest('bash',['alias python233=python2','python233 --version 2>&1'])

以上代码 大概意思是,输入bash,并开启交互式shell

第一次流写入alias python233=python2 并且回车
第二次流写入python233 --version 2>&1 并且回车
输出流提示
提示python233不存在
PS: python --version竟然输出到错误流 真离谱

无名啊 8楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

多条命令设置别名以及使用别名命令【失败】

贴下代码?

无名啊 7楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt.

需要在交互式模式,或者启用expand_aliasesalias才能生效

弟妹 6楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)
@无名啊,是的 因为我是子进程打开的shell 我无法做到输入两条命令,因为我不是在tty下进行输入的
无名啊 5楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹

  1. Bash 总是至少读取完整的一行

    读取alias lll='ls -ll';lll

  2. 接着立即扩展别名

    alias不是别名,lll也不是别名(你的alias lll='ls-ll'此时还未执行),所以不用扩展

  3. 最后再执行命令

    1. 执行alias lll='ls -ll'
    2. 执行lll
弟妹 4楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)
@无名啊,抱歉 我不是用我举得例子测试的。我现在明白了,不加引号,是参数没有携带。并且会提示alias 没有ll参数
现在明白你引用的大意了,所以我补充了我的需求场景,明白alias不符合我的要求了
无名啊 3楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

@弟妹,看来你是没看懂大意,也没看英文原文呐。。

弟妹 2楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)
并不行哦
ubuntu@ubuntu:~$ alias lll='ls-ll';lll

Command 'lll' not found, did you mean:

  command 'llc' from deb llvm
  command 'dll' from deb brickos
  command 'llt' from deb storebackup
  command 'lli' from deb llvm-runtime

Try: sudo apt install <deb name>
无名啊 1楼回复 弟妹请问为什么下面的linux命令不能生效? (2022-08-16//)

Bash 手册里,Alias 条目说:

Bash always reads at least one complete line of input, and all lines that make up a compound command, before executing any of the commands on that line or the compound command. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not affected by the new alias.

大意:

Bash 总是至少读取完整的一行(或多行,保证复合命令也读完整咯),接着立即扩展别名,最后再执行命令

另外,你的ls -ll需要用引号括起来,否则-ll不是lll的一部分,而是成为alias的参数。如:

$ alias lll='ls -ll'
Curtion 1楼回复 艾木友尔尔巴win10子系统出现故障 (2022-08-16//)

企业微信截图_16606193826612.png(29.53 KB)
红米K30 Pro(变焦版)

tasy5kg 23楼回复 tasy5kg【小萌 GIF】13.0 版 (2022-08-16//)

@老虎会游泳,我可以使用 虎绿林 API,为 小萌 GIF 开发“检查更新”的功能吗?

我的想法是:

  • 当用户主动使用 小萌 GIF 时,应用自动在后台通过 虎绿林 API 访问本帖,查看帖子内容是否有新版。
  • 如果有新版,引导用户通过浏览器打开本帖,下载新版。
  • 每日最多自动访问 虎绿林 API 检查更新一次。
  • 不会对虎绿林附件下载链接进行盗链。
tasy5kg 22楼回复 tasy5kg【小萌 GIF】13.0 版 (2022-08-15//)
@花花世界,我更新了第 8 版,可以截取视频片段了。
tasy5kg 21楼回复 tasy5kg【小萌 GIF】13.0 版 (2022-08-15//)
@TabKey9,改进了对于 Android 9.0 及以下版本的适配,现在转换 GIF 时可以直接保存,不用再多点一下了。

另外第 8 版增加和改进了许多功能,推荐更新。
胡图图 4楼回复 胡图图4k的屏幕怎么一分为4 (2022-08-15//)

@水木易安,我想分一个1/4的区域,拿来打1080p的游戏,用obs感觉延迟太高,玩不了
127.9.147.96

下一页 上一页 (338 / 577页)

11月12日 13:27 星期三

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1