Bash interactive scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash interactive scripts
# 1  
Old 10-19-2016
Bash interactive scripts

i have a script that contains:

script.sh
Code:
#!/bin/bash
echo -e "\t\t\t0. Exit"
echo -e "\t\t\t1. Help"
echo -e "\t\t\t2. Notes"
echo -e "\t\t\t3. Classes"
echo "${newline}"
echo -n -e "\t Please enter option number :  "
read Type
case $Type in
     1)
        clear
      /home/admin/ip1.sh
          ;;
     2)
       clear
              /home/admin/mainmenu.sh
          ;;
     3)
        clear
          echo "Currently Not supported"
              /home/admin/mainmenu.sh
          ;;
     *)
        clear
          echo "You have entered Wrong Entry"
              /home/admin/mainmenu.sh
          ;;
esac

under normal circumstances, if this script is run the usual way "./script.sh" from the commandline, it works. However, i need to run this script through a pipe. and i cant seem to get it to work.

this technique is suppose to work:

Code:
bash -c "$(cat script.sh)"

but when i run it, it runs, but immediately exits without waiting for the user to provide a response. So the error message I end up getting is:

Code:
You have entered Wrong Entry

# 2  
Old 10-19-2016
The thing is, "read" reads from standard input. When you feed the script into bash via a pipe, what's standard input? Your script. There's nowhere left to read commands from.

You could force /dev/tty -- except there is no /dev/tty, because there's no human at the keys. That only works interactively.

If possible, I would modify it to accept an optional commandline argument, i.e.

Code:
Type="$1"
[ -z "$1" ] && read Type

Then you could do bash -s -- 1 < script.sh and feed it argument 1.
These 2 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash -c interactive scripts

i have to run the following script through a pipe: script.sh: #!/bin/bash echo "Hello World" echo -e "The \033 here's how its currently being run: bash -c "$(cat script.sh)" This is an interactive script. the problem is, when i run it this way, if you go to another terminal and... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Identifying interactive scripts

so for the purposes of this thread, interactive scripts are shell scripts that prompts for a response from a user and then waits for the user to enter a response before proceeding. now, from my understanding of this, the one common string i can expect to find in all interactive scripts is some... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Bash interactive Script Required

Dear All, Please help in creating a bash script to fetch records from multiple files the script should ask inputs of file type and column level input(at least 4 col of each file type) I have 4 sort of Files, A,B,C,D. file names are like A_0112.unl, A_01215.unl, A_0001.unl and same with B C... (3 Replies)
Discussion started by: Muhammad Ali
3 Replies

4. Shell Programming and Scripting

Non interactive su in bash script

Hi, I have a python gui which allow users entering the root password, then a bash script is called to run "su" with the root password on the background. I could find a way to run "su" with a password. How to run "su" in a bash script without password prompt? Thank you. (4 Replies)
Discussion started by: hce
4 Replies

5. Shell Programming and Scripting

interactive scripts with user input that includes quotes

I'm writing a basic ldapsearch script that prompts the user for their search criteria. The input they're being asked for is the search filter portion of the ldapsearch command. This string must be quoted. When the script executes the command it returns nothing. If I hard code a search filter it... (1 Reply)
Discussion started by: donniemac
1 Replies

6. Shell Programming and Scripting

Interactive scripts for Oracle

Hello friends, I am a ORACLE user, we have some internal database file, lets say "demo.config" and an internal tool to patch this file....lets call that tool as "dbfixer". We have 100's-1000's of such files "demo.config" which need to get patched by the tool. So we need to write a script ...... (1 Reply)
Discussion started by: Newbie456267uni
1 Replies

7. Shell Programming and Scripting

Bash interactive installation script

Hi, for an exercise I need to write a script that will ask the user about each package in a (local) repository and install it or not according to the user's input. I am fairly new to scripting, so I did not get very far. Here is what I came up with. I really appreciate your help. ... (1 Reply)
Discussion started by: Softsmid
1 Replies

8. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

9. Shell Programming and Scripting

Automating interactive scripts

Hi all, I am trying to write a program that will automate interactive scripts that use 'pkgadd'. Easily enough I can use 'pkgask' and a response file for most of what I want to do, but unfortunately there are parts of some pkg installations that are configured to only take input from /dev/tty!!... (2 Replies)
Discussion started by: bookoo
2 Replies
Login or Register to Ask a Question