0

i need some help with a shell script. I want to start a shell witch is asking for some informations. This should be saved into variables and after entering the informations it should be written in a file.

Something like that:

call shell script

"tell me your name"
John

After this it should write in a file "his name is John"

I know it is a very stupid example, but if i know how to handle this i can adapt this in my special use-case.

Thanks in advance :)

5 Answers 5

3
#!/bin/bash
echo -n "Whats your name? "
read name
echo $name > name.txt
Sign up to request clarification or add additional context in comments.

Comments

3

It's a bit cleaner to have the read command print the prompt, using its -p option:

#!/bin/bash
read -p "Tell me your name: " name
echo "His name is $name" >name.txt

Comments

1

Use echo to print, read to read input.

echo -n "Tell me your name: "
read name
echo "Your name is $name."

Comments

1
#!/bin/bash
echo "Tell me your name?"
read name
echo "His name is $name" > name.txt

Comments

0

If you want to append to exiting file

1. echo -n "Tell me your name: "
2. read name
3. echo $name >> fileName.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.