@无名啊,我知道7楼这个方案,因为机器没网,电脑里没有这个软件。所以就没采用这个。。。
使用的交互式shell,是不好用的。
然后,我是拿python2.7测试--version输出到错误流的(我还没测试其他机器的2.7是否也这样)
@弟妹,
PS: python --version竟然输出到错误流 真离谱
我瞅了瞅,应该是输出至
stdout
的?$ python3 --version | sed 's/^/[STDOUT] /' [STDOUT] Python 3.10.5
@弟妹,看来,你没看 7 楼
await execRequest('bash',['shopt -s expand_aliases', 'alias python233=python2', 'python233 --version 2>&1'])
@无名啊,以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竟然输出到错误流 真离谱
@弟妹,
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt.
需要在交互式模式,或者启用
expand_aliases
,alias
才能生效
@无名啊,是的 因为我是子进程打开的shell 我无法做到输入两条命令,因为我不是在tty下进行输入的
@弟妹,
Bash 总是至少读取完整的一行
读取
alias lll='ls -ll';lll
接着立即扩展别名
alias
不是别名,lll
也不是别名(你的alias lll='ls-ll'
此时还未执行),所以不用扩展最后再执行命令
- 执行
alias lll='ls -ll'
- 执行
lll
@无名啊,抱歉 我不是用我举得例子测试的。我现在明白了,不加引号,是参数没有携带。并且会提示alias 没有ll参数
现在明白你引用的大意了,所以我补充了我的需求场景,明白alias不符合我的要求了
@弟妹,看来你是没看懂大意,也没看英文原文呐。。
并不行哦
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>
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'
红米K30 Pro(变焦版)
@老虎会游泳,我可以使用 虎绿林 API,为 小萌 GIF 开发“检查更新”的功能吗?
我的想法是:
- 当用户主动使用 小萌 GIF 时,应用自动在后台通过 虎绿林 API 访问本帖,查看帖子内容是否有新版。
- 如果有新版,引导用户通过浏览器打开本帖,下载新版。
- 每日最多自动访问 虎绿林 API 检查更新一次。
- 不会对虎绿林附件下载链接进行盗链。
@花花世界,我更新了第 8 版,可以截取视频片段了。
@TabKey9,改进了对于 Android 9.0 及以下版本的适配,现在转换 GIF 时可以直接保存,不用再多点一下了。
另外第 8 版增加和改进了许多功能,推荐更新。
@水木易安,我想分一个1/4的区域,拿来打1080p的游戏,用obs感觉延迟太高,玩不了
127.9.147.96
@罐子,
一加8Pro
@罐子,
一加8Pro
4k就好好的用200%啊
小米MIX2s(白)