[h1=0
store_newgolf="home/john1/learning/store_newgolf"
while (( "$h1"<4))
do
read -p "Enter hole number : " h1
read -p "Enter par : " p1
read -p "Enter strokes : " s1
read -p "Enter fairways hit : " f1
read -p "Enter greens in regulation : " g1
read -p "Enter putting strokes : " ps1
echo "hole number-$h1"
echo "par-$p1"
echo " strokes- $s1"
echo "fairways hit - $f1"
echo "greens in regulation - $ g1"
echo "putting strokes-$ps1"
printf "$h1":"$p1:"$s1":"f1":"$g1":"ps1" >> "store_newgolf"
done]
Hello, I am new at bash scripting and cannot get this script to print on separate lines in the file "store_newgolf" Any help would be greatly appreciated. Also when trying to write a loop I came across this code [- le ] I could not find any explanation for this. What does this mean? Thank you for your assistance.
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
[SOLVED!]Bash scripting questions
[SOLVED!]Bash scripting questions
Last edited by tony763 on 2017-06-28 17:20, edited 2 times in total.
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Bash scripting questions
That does not look like any kind of bash script I have seen.
Any bash script starts with:
I am not any kind of expert on bash, but even if I was, I would not
start writing a complete tutorial in a forum post, especially when
there are so many readily available on line.
I think your best approach would be to start with some bash tutorial,
there are many:
How to start writing a bash script
One of many:
https://www.linux.com/learn/writing-simple-bash-script
This statement is puzzling :
you come across other code that you do not know what it does ?
trying to do is copy/paste other code that some one else wrote, with out having
a clue as to what the code actually does.
That is not a good practice at all, and not wise. You could easily copy/paste something into a script , that does things you really don't want to have happen.
On the same :
It means " less than or equal to "
and
A simple search would have give a explanation :
what does the [- le ] in a loop mean
This is from the first hit at:
https://stackoverflow.com/questions/837 ... while-loop
is help full.
How to write loops with bash
For details on writing various loops.
Any bash script starts with:
Code: Select all
#!/bin/bash
start writing a complete tutorial in a forum post, especially when
there are so many readily available on line.
I think your best approach would be to start with some bash tutorial,
there are many:
How to start writing a bash script
One of many:
https://www.linux.com/learn/writing-simple-bash-script
This statement is puzzling :
If you are trying to write a loop, ok, so you start writing your code, How is itAlso when trying to write a loop I came across this code [- le ]---snip--
you come across other code that you do not know what it does ?
It appears to me, you are not actually writing anything, what you are doing orI could not find any explanation for this. What does this mean?
trying to do is copy/paste other code that some one else wrote, with out having
a clue as to what the code actually does.
That is not a good practice at all, and not wise. You could easily copy/paste something into a script , that does things you really don't want to have happen.
On the same :
You did not really look anywhere did you ?Also when trying to write a loop I came across this codeI could not find any explanation for this.Code: Select all
[- le ]
It means " less than or equal to "
and
A simple search would have give a explanation :
what does the [- le ] in a loop mean
This is from the first hit at:
https://stackoverflow.com/questions/837 ... while-loop
Code: Select all
man test
Also :n1 -lt n2
True if the integer n1 is algebraically less than the integer n2.
n1 -le n2
True if the integer n1 is algebraically less than or equal to the
integer n2.
Code: Select all
man bash
is help full.
How to write loops with bash
For details on writing various loops.
Last edited by GarryRicketson on 2017-06-28 05:52, edited 1 time in total.
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
-
- Posts: 1101
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Bash scripting questions
There are a couple of minor issues with your code, I have rectified them and tested it for you, save this as a separate file and run diff file1 file2 to see the differences.
Code: Select all
h1=0
store_newgolf="/home/john1/learning/store_newgolf"
while (( "$h1"<4))
do
read -p "Enter hole number : " h1
read -p "Enter par : " p1
read -p "Enter strokes : " s1
read -p "Enter fairways hit : " f1
read -p "Enter greens in regulation : " g1
read -p "Enter putting strokes : " ps1
echo "hole number - $h1"
echo "par - $p1"
echo "strokes - $s1"
echo "fairways hit - $f1"
echo "greens in regulation - $g1"
echo "putting strokes - $ps1"
printf "$h1":"$p1":"$s1":"$f1":"$g1":"$ps1\n" >> "$store_newgolf"
done
Re: Bash scripting questions
Dear GarryRicketson and Dai_trying,
Thank you both for taking the time to help me with my problem! I really appreciate your suggestions, advice and comments. I found them very helpful and informative.
The script runs correctly now and I have learned a lot!
Thank you for the help!
Thank you both for taking the time to help me with my problem! I really appreciate your suggestions, advice and comments. I found them very helpful and informative.
The script runs correctly now and I have learned a lot!
Thank you for the help!
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
-
- Posts: 1101
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: [SOLVED!]Bash scripting questions
This beginners guide has been very useful to me in the past and I still use it for reference.