I have problem executing a simple script in bash. The script is like this:
#! /bin/sh
read -p 'press  [ENTER]  to continue deleting line'
sudo sed -ie '$d' /home/hpccuser/.profile
and when I execute the script with ./script the output is like this:
press  [ENTER]  to continue deleting line./script: 3: read: arg count
[sudo] password for user
I run the read command directly in terminal (copy and paste from script to terminal) and it works fine; it waits for an ENTER to be hit (just like a pause).
Because your script starts with #!/bin/sh rather than #!/bin/bash, you aren't guaranteed to have bash extensions (such as read -p) available, and can rely only on standards-compliant functionality.
See the relevant standards document for a list of functionality guaranteed to be present in read.
In this case, you'd probably want two lines, one doing the print, and the other doing the read:
printf 'press [ENTER] to continue deleting...'
read _
                        You can do this with echo command too!:
    echo "press  [ENTER]  to continue deleting line"
    read continue
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With