Home > other >  why does readline think I am pressing the "d" key?
why does readline think I am pressing the "d" key?

Time:01-30

I have two scripts. test4.sh calls 1.sh
I don’t understand why 1.sh things I am pressing the “d” key. Can you explain please

Here is 1.sh

set -x
echo "Please enter some input: "
echo "enter $(echo $RANDOM)"
sleep 2
read input_variable
echo "You entered: $input_variable"

Here is test4.sh

set -x
set  e
mkfifo p_in
bash 1.sh p_in<0 | sed -e 's/^/1\.sh:: /'  &
cat - 1> p_in

Output:

pi@raspberrypi:~/tmp/lolttt $ bash test4.sh
  set  e
  mkfifo p_in
mkfifo: cannot create fifo 'p_in': File exists
  bash 1.sh p_in
  cat -
  sed -e 's/^/1\.sh:: /'
  echo 'Please enter some input: '
1.sh:: Please enter some input:
   echo 23876
  echo 'enter 23876'
1.sh:: enter 23876
  sleep 2
  read input_variable
  echo 'You entered: d'
1.sh:: You entered: d

This weird behaviour does not happen if I run 1.sh directly from bash. This weird behaviour only happens from test4.sh

Help please?

CodePudding user response:

Because you have a file named 0 in your current working directory with the content d.

bash 1.sh p_in<0 - is equal to bash 1.sh p_in <0 - runs command 1.sh with argument p_in with file named 0 redirected to standard input.

I think you want bash 1.sh 0<p_in. On the left is file descriptor. Or just <p_in without 0, the default input is file descriptor 0.

  • Related