0

I have the following bash script. I want it to wait after opening up.

For example, after running ./script 001 homework pico I want read a key and then pico to open up and then save to the address. But it does not wait to read a key

#!/bin/sh

link="Grades"

classhome="/afs/class"

if [ $# > 3 || $# < 2 ]
then
echo "Usage: enter-grades <section> <gradefile> <?editor>"
echo "    enter new grades for section <section> <?editor>."
echo "    e.g. enter-grades 401 quiz5 [pico]"
exit 1
fi

section=$1
grade=$2
editor=$3

if [ -z "$editor" ]
then
editor="cat >";
fi


if [ ! -d "$classhome/$section" ]
then
echo "enter-grade: No such section $section"
exit 1;
fi

cd $classhome/$section

echo "If you need to make any changes, wait until this script is done."
echo "Then use your favorite editor."

for n in *
do
  if [ -s $n/$link/$grade ]
  then
    echo "Grade file $grade for $n already exists!"
    cat $n/$link/$grade
  else
    echo "Please enter $grade grade for $n, press return and then Control-D"
    read -n 1 -p "Press any key to continue... "
    eval $editor $n/$link/$grade
    wait
  fi
done
Node.JS
  • 1,042
  • 6
  • 44
  • 114
  • Is this actually being run by `bash`? `/bin/sh` may be a different shell on your machine, one that doesn't understand the `-n` flag. – chepner Nov 06 '19 at 01:17
  • I use ubuntu and I run it like this ./script – Node.JS Nov 06 '19 at 01:17
  • There is already a standard way to specify the desired editor: use `$EDITOR $n/$link/$grade`, and let the user set `EDITOR` in their environment. – chepner Nov 06 '19 at 01:17
  • ubuntu doesn't use `bash` for `/bin/sh`; change the shebang to `#!/bin/bash`. – chepner Nov 06 '19 at 01:18
  • @chepner it did the trick. Thank you – Node.JS Nov 06 '19 at 01:19
  • I thought sh and bash are the same – Node.JS Nov 06 '19 at 01:19
  • 2
    No, they are not. `bash` is a specific shell; `/bin/sh` is an abstract name indicating a shell that follows the POSIX standard for shell languages. On most machines, `/bin/sh` will be a copy of or a link to some other shell. Sometimes, it's `bash`, but on Ubuntu, it's `dash`. – chepner Nov 06 '19 at 01:22

0 Answers0