Question

I want to create a email script that really is a texting script that is using the mail -x and sending to numbers. It would go something like this:

#/bin/sh

Joe=8881235555
Bob=8881235556

echo "Who do you want to text?:(i.e. Joe, Bob, etc)"
read name
echo "What do you want to say?:)"
read quote
echo "texting $name with $quote"

echo $variablequote | mailx -s "Text Message via email" $variablename@txt.att.net

How do I get that user input name to transfer in to a preset value?

No correct solution

OTHER TIPS

Consider using a more modern shell:

#!/bin/bash

# Use an associative array, and map names to numbers
declare -A numbers
numbers=([Joe]=8881235555  [Bob]=8881235556)

echo "Who do you want to text?:(i.e. Joe, Bob, etc)"
read name
echo "What do you want to say?:)"
read quote

# Look up number by name
number=${numbers[$name]}

if [[ $number ]] 
then
  echo "texting $name ($number) with $quote"
  mailx -s "Text Message via email" "$number@txt.att.net" <<< "$quote"
else
  echo "Unknown user"
  exit 1
fi

If you want to use /bin/sh:

#!/bin/sh

# Prefix the numbers with something
number_Joe=8881235555
number_Bob=8881235556

echo "Who do you want to text?:(i.e. Joe, Bob, etc)"
read name
echo "What do you want to say?:)"
read quote

# Remove any dangerous characters that the user enters
sanitized=$(printf "%s" "$name" | tr -cd 'a-zA-Z')

# Look up by evaluating e.g. "number=$number_Joe"
eval "number=\$number_$sanitized"

if [ "$number" ] 
then
    echo "texting $name ($number) with $quote"
    printf "%s\n" "$quote" | mailx -s "Text Message via email" "$number@txt.att.net"
else
  echo "Unknown user"
  exit 1
fi
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top