Celsius to Fahrenheit Linux Shell Script [Bash Shell Script]

To create script file type command 'touch filename.sh'

To give executable persimmison run command 'chmod +x filename.sh'

To convert from celsius to fahrenheit we use formula F = (C*9/5)+32

For printing message on screen we use 'echo' command

To take input from the user we use 'read' command

Shell Script to Convert Celsius to Fahrenheit Temperature

            
#!/bin/bash

echo "Enter temperature in Celsius: "
read celsius
                
# formula to convert Celsius to Fahrenheit: F = (C * 9/5) + 32
fahrenheit=$(echo "scale=2;($celsius * 9/5) + 32" | bc)
                
echo "${celsius}°C is equal to ${fahrenheit}°F"
                
            
        

Save the Script and to run script open terminal change directory to the location of the time type command './filename.sh' press enter button to run the script

أحدث أقدم