gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Develop a script in bash that takes the temperature value in Celsius OR Kelvins and…
- User
Develop a script in bash that takes the temperature value in Celsius OR Kelvins and returns the inverse value. The formula is pretty simple: C = K - 273; K = C + 273. It should return a single line with no spaces, like: ./temp.sh 122K -> -151C
- Assistant
Here is a script in bash that accomplishes this task:
#!/bin/bash # Extract the value and unit from the input argument input=$1 value=${input::-1} unit=${input: -1} # Check if temperature is in Celsius or Kelvins if [ $unit == "C" ]; then # Convert Celsius to Kelvins inverse=$(echo "scale=0; $value + 273" | bc) echo "$inverse""K" elif [ $unit == "K" ]; then # Convert Kelvins to Celsius inverse=$(echo "scale=0; $value - 273" | bc) echo "$inverse""C" else echo "Invalid input format. Please provide a temperature value in Celsius (C) or Kelvins (K)." fiSave this script in a file called
temp.shand make it executable withchmod +x temp.sh. You can then run the script with an input argument like./temp.sh 122Kto get the inverse temperature value. The script will output the result in the format you specified.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.