Solved

Linux bash script to change argument to lowercase

Posted on 2011-03-07
3
469 Views
Last Modified: 2012-06-27
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
Comment
Question by:ipconfig610
  • 2
3 Comments
 
LVL 2

Expert Comment

by:P-Y
Comment Utility
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
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
Comment Utility
CONTEXT=$(echo ${1} | tr [[:upper:]] [[:lower:]])
MACADD=$(echo ${2} | tr [[:upper:]] [[:lower:]])
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now