Using input from read to allow user to designate a specific volume


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using input from read to allow user to designate a specific volume
# 1  
Old 12-04-2017
Error Using input from read to allow user to designate a specific volume

I am attempting to script the creation of MacOS installation flash media using read to allow the user to designate the name of the volume and store it in the variable VOLNAME. When I run the script, and input the name of the volume, I get the error:
Code:
': not a valid identifier: `VOLNAME
HSInstaller: line 7: VOLNAME: command not found

Code:
#!/bin/sh
# script for creating High Sierra installation media
# Get name of USB drive Volume
echo "Volume name to be used to create installation media (current volume content will be erased)"
read VOLNAME
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/$(VOLNAME)

I was able to use a similar substitution in a script to connect a network share without issue:
Code:
#!/bin/sh
# script for connecting to file shares.
# Get UserID and password.
echo " UID"
read UID
echo "Password"
read -s password
# Have user provide path
echo "Provide the network path to the directory you wish to connect to."
echo "use the following format:server/directory/directory"
echo "for example AR101/Dir/Team"
read NetPth
open smb://$UID:$password@$NetPth

I've had no issues with the second script. Not sure why the first is unable to use the input given. Any advice would be appreciated.

Moderator's Comments:
Mod Comment Please use CODE tags for data / output as well as required by forum rules!

Last edited by RudiC; 12-04-2017 at 08:30 AM.. Reason: Added CODE tags.
# 2  
Old 12-04-2017
What you use is "command substitution" $(...) (in a form not necessarily provided by your sh shell), but you need variable expansion ${...}.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-04-2017
Thank you for the reply. I did as you suggested, and changed
Code:
--volume /Volumes/$(VOLNAME)

to
Code:
--volume /Volumes/${VOLNAME}

but still get the same error. I get it when I used
Code:
--volume /Volumes/$VOLNAME

as well (in the first iteration of this I had attempted). The error
Code:
': not a valid identifier: `VOLNAME
HSInstaller: line 7: VOLNAME: command not found

is curious, as the leading single quote seems like it belongs at the end of the line behind 'VOLNAME and the incorrect encapsulation appears to be making it read the variable as a command. Is there another way to pass the input?
# 4  
Old 12-04-2017
Do you have DOS line terminators <CR> (\r, 0x0D, ^M)? Does "creation of MacOS installation flash media" mean you're running everything on a MacOS? What's your OS and shell versions?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-04-2017
I am doing this on MacOS High Sierra using Terminal version 2.8. The file was originally created in Notepad++ on a Windows PC with the .bash file extension. It has since been edited in VIM from the CLI on the MacBook, and the file extension on the end of the file name was dropped.
Code:
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.

Edit:
Do you think I picked up unprintable characters when creating this in NP++? It's usually very good about keeping files appropriate to the type designated (hence the .bash extension I saved with). I guess I try recreating the file directly in VIM to see if that remedies the problem.

---------- Post updated at 09:36 AM ---------- Previous update was at 09:04 AM ----------

That was it. I remade the file line for line in VIM and it works like a charm. I noticed that the original file in VIM had the following as I was looking at it to transcribe the new file:
Code:
"HSInstaller" [dos] 7L, 333C

Thank you so much for your help, I can't believe I overlooked that as many times as I had the file open in VIM.

Last edited by kevinamygrayson; 12-04-2017 at 10:19 AM.. Reason: adding a question
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

2. Shell Programming and Scripting

Shell read command is not waiting for user input

Hi, i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block. while read line; do command 1; command 2 echo -n "Do you want to continute > " read rsp... (2 Replies)
Discussion started by: ranvijaidba
2 Replies

3. Shell Programming and Scripting

Perl to read user input

I am creating a bash that uses perl . The below code closes before the input is entered. If I run the perl as a .pl it is fine. What am I doing wrong? Thank you :). #!/bin/bash cd 'C:\Users\cmccabe\Desktop\wget' wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv print... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Using read to prompt for editable user input in Bash 3

Below is a simple script to prompt for user input while suggesting an editable default value at the prompt: shortname=user1 read -e -i $shortname -p "Please enter the username you would like to add: " input USERNAME="${input:-$shortname}" Please enter the username you would like to add:... (3 Replies)
Discussion started by: woodson2
3 Replies

5. Homework & Coursework Questions

How to read user keyboard input inside the case?

I need to Write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. with automated following tasks: Copy directory tree Delete files or directories Output Information (this part is done ) *Copy directory tree The “Copy... (2 Replies)
Discussion started by: femchi
2 Replies

6. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

7. Shell Programming and Scripting

Solaris- Read command from user input

I need to write a bourne shell script (solaris 10) that accepts input from the user. The input will be a command- any command like ls/ pwd/ mv etc. After the input is read, the shell must execute the command supplied by the user. I know we use read to play with user inputs. Just not sure how to... (2 Replies)
Discussion started by: PDManc
2 Replies

8. UNIX for Dummies Questions & Answers

How to read a line of text from user input?

Hiii I wanna a read a line of text from standard input. The user enter data like this way name phone_no month1_salary month2_salary that is user enter the name ,phone no and salary of 2 months in a single line by giving spaces. I wanna add the 3rd and 4th fields ...ie add both... (4 Replies)
Discussion started by: krishnampkkm
4 Replies

9. UNIX for Dummies Questions & Answers

getline to read input from a user

Hi, The gcc compiler has warned about using gets(), so I've been trying my hand at getline. Problem is that I've been able to read from a file, but what I really need is to read from a user's input. I want to use getline like a scanf() command, but I can't figure what to substitute for the fp... (6 Replies)
Discussion started by: sdsd
6 Replies

10. UNIX for Dummies Questions & Answers

read user input from within a wile loop that is being fed from below

hi! i need to do a ksh script that uses a wile loop that is fed form below while read line do some things done < myfile inside the while loop i need to read user input to ask the user what he wants to do, but "read" reads the file, and not the standard input while read line do ... (2 Replies)
Discussion started by: broli
2 Replies
Login or Register to Ask a Question