• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

Linux bash script to change argument to lowercase

I have the following script which works great if the user types both arguments in all lower case.  If the user of the script types the command with any upper case letters the script will fail.  I am sure there must be a way for the user input to be proceed in all lower case.

The 2 arguments in my script are: ${CONTEXT} and  ${MACADD}

Thanks


#!/bin/bash
#
if [ -z ${2} ]
then
    echo "usage: $0 <contextname> <macaddress>"
    exit 1
fi
CONTEXT=${1}
MACADD=${2}
cat /var/softswitch/configs/device/polycom/${CONTEXT}/${MACADD}-boot.log

Open in new window

0
ipconfig610
Asked:
ipconfig610
  • 2
1 Solution
 
P-YCommented:
Try this:

#!/bin/bash
#
if [ -z ${2} ]
then
    echo "usage: $0 <contextname> <macaddress>"
    exit 1
fi
CONTEXT=${1} | tr '[A-Z]' '[a-z]'
MACADD=${2} | tr '[A-Z]' '[a-z]'
cat /var/softswitch/configs/device/polycom/${CONTEXT}/${MACADD}-boot.log
0
 
farzanjCommented:
CONTEXT=$(echo ${1} | tr [[:upper:]] [[:lower:]])
MACADD=$(echo ${2} | tr [[:upper:]] [[:lower:]])
0
 
farzanjCommented:
Newer versions of bash also let you do this at the top of the script.  This should fix any problems you are having.

declare -l CONTEXT MACADD

Open in new window


Older versions don't understand it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now