I know that this question is answered many times, but I still can't figure out how to do it. Maybe it's because I don't know the correct keyword to search for.

Using

echo -ne '\n' | enter

doesn't work. My code is:

#! /bin/bash
#Grub-customizer
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
echo -ne '\n' | return
sudo apt-get update
sudo apt-get install grub-customizer
有帮助吗?

解决方案

You're supposed to pipe the \n into the command that's going to be receiving it (otherwise it won't ever see it!):

echo -ne '\n' | sudo add-apt-repository ppa:danielrichter2007/grub-customizer
echo -ne '\n' | sudo apt-get install grub-customizer

Now, the right solution here would instead be to use the -y flags instead:

sudo add-apt-repository -y ppa:danielrichter2007/grub-customizer
sudo apt-get install -y grub-customizer

其他提示

'echo -ne "\n" | ./create.sh \n', // this command is for pressing enter each time the shell script is asking user to press enter
'echo -ne "\n" | yourcommand \n', //tempate 

  const client = new Client();
  const cmds = [
    'ls -lah \n', // \n is important 
    'cd /mnt \n',
    'echo -ne "\n" | ./create.sh \n', // this command is for pressing enter each time the shell script is asking user to press enter
    'pwd \n',
    'ls -lah \n',
    'exit \n',
  ];
  client.on('ready', () => {
      console.log('Client :: ready');
      client.shell((err, stream) => {
        stream.on('close', (code) => {
          console.log('stream :: close\n', { code });
        }).on('data', (myData) => {
          console.log('stream :: data\n', myData.toString());
        }).on('exit', (code) => {
          console.log('stream :: exit\n', { code });
          client.end();
        }).on('error', (e) => {
          console.log('stream :: error\n', { e });
          rej(e);
        });
        for (let i = 0; i < cmds.length; i += 1) {
          const cmd = cmds[i];
          stream.write(`${cmd}`);
        }
      });
    }).connect({
    host: '127.0.0.1',
    port: 22,
    username: 'root',
    password: 'root',
  });

Reference Click HERE

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top