Bash exercise
orque
Posted messages
17
Registration date
Status
Member
Last intervention
-
sov^36 Posted messages 3624 Registration date Status Contributor Last intervention -
sov^36 Posted messages 3624 Registration date Status Contributor Last intervention -
Hello,
please, how to read from a file when working on the bash shell
the exercise is as follows for more information:
create a script called "convertisseur" that allows you to convert an amount in Francs passed as an argument into Euros. The conversion rate will be contained in a file named Taux in the form: Taux: 6.55957. Remember to test if this file exists and is readable by your process. If not, your script should display an error and exit with a return code of 1
please, how to read from a file when working on the bash shell
the exercise is as follows for more information:
create a script called "convertisseur" that allows you to convert an amount in Francs passed as an argument into Euros. The conversion rate will be contained in a file named Taux in the form: Taux: 6.55957. Remember to test if this file exists and is readable by your process. If not, your script should display an error and exit with a return code of 1
Configuration: Linux Suse Firefox 2.0
4 answers
more 'the file name' to read a text file in bash.
finally, for example, you also have vi, emacs, less, etc....
good luck with your script :)
finally, for example, you also have vi, emacs, less, etc....
good luck with your script :)
For the first part
[johand@horus]~ $echo $SHELL
/bin/bash
[johand@horus]~ $echo $(basename $SHELL)
bash
Then use test, [ ... etc
--
Gates vous a donné les fenêtres.
GNU nous a donné toute la maison. (Alexandrin)
[johand@horus]~ $echo $SHELL
/bin/bash
[johand@horus]~ $echo $(basename $SHELL)
bash
Then use test, [ ... etc
--
Gates vous a donné les fenêtres.
GNU nous a donné toute la maison. (Alexandrin)
I sketch a solution I'm not a pro in bash and I don't want to do your exercise :P
place your convertisseur.sh script in the same directory as your taux.txt
#!/bin/bash
#converter
function conversion () {
let euros=$somme/$taux
return euros
}
function assignrate {
taux="more taux.txt | cut -d 'Rate :' " #selects the rate value from the taux.txt file
if [ taux != ??]
return 0
}
assignment ()
echo "MACHINE CONVERTER BY THING"
echo "What amount do you want to convert? (in Francs)"
read somme
assignment ()
conversion (somme)
echo "$somme"
it must be full of errors: I don't remember how to pass parameters in a function in bash or how to check for the presence of the file... but it's always a lead ;)
--
omFg
place your convertisseur.sh script in the same directory as your taux.txt
#!/bin/bash
#converter
function conversion () {
let euros=$somme/$taux
return euros
}
function assignrate {
taux="more taux.txt | cut -d 'Rate :' " #selects the rate value from the taux.txt file
if [ taux != ??]
return 0
}
assignment ()
echo "MACHINE CONVERTER BY THING"
echo "What amount do you want to convert? (in Francs)"
read somme
assignment ()
conversion (somme)
echo "$somme"
it must be full of errors: I don't remember how to pass parameters in a function in bash or how to check for the presence of the file... but it's always a lead ;)
--
omFg