找到9个回复 (用户: 弟妹)
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-17回复 / /

    @无名啊,加上shopt -s expand_aliases 可以了 谢谢大佬。

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

    我的理解跟编程语言无关,我是fork出来的子进程来启动bash命令,这个bash命令不会立刻退出,可以等待我输入,我就可以输入流写入数据,我称它为“交互式” 😂(1. 也可能默认开启了tty 2.也可能没有收到终止信号,所以一直等待)

    和实际 交互式登录SHELL 非交互式登录SHELL概念是否一样,我并没有仔细研究

  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,好的,谢谢。我明天试试10楼的。
    你写的那个参数,我之前查资料是bash这个shell才有的好像。zsh好像没有
    shopt is not a command, but a shell built-in. bash knows what to do with it because it's a bash built-in , but zsh has no idea what it is. You'll want to look into setopt which is a zsh built-in, and put those values into a new .zshrc script.
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,shopt 这个软件我电脑没有。。


    22:50 测试发现,原来是我用的zsh没有。我没具体看这个报错,我明天再试试

    shopt is not a command, but a shell built-in. bash knows what to do with it because it's a bash built-in , but zsh has no idea what it is. You'll want to look into setopt which is a zsh built-in, and put those values into a new .zshrc script.
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,我是python2 2>file.err 这么测试的,sed我是不太会用
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,我知道7楼这个方案,因为机器没网,电脑里没有这个软件。所以就没采用这个。。。

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

    然后,我是拿python2.7测试--version输出到错误流的(我还没测试其他机器的2.7是否也这样)
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 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竟然输出到错误流 真离谱

  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,是的 因为我是子进程打开的shell 我无法做到输入两条命令,因为我不是在tty下进行输入的
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 2022-08-16回复 / /
    @无名啊,抱歉 我不是用我举得例子测试的。我现在明白了,不加引号,是参数没有携带。并且会提示alias 没有ll参数
    现在明白你引用的大意了,所以我补充了我的需求场景,明白alias不符合我的要求了
  • 请问为什么下面的linux命令不能生效?
    26743点击 / 2022-08-16发布 / 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>