?
Solved

Linux bash script to change argument to lowercase

Posted on 2011-03-07
3
Medium Priority
?
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:P-Y
ID: 35059669
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 2000 total points
ID: 35059689
CONTEXT=$(echo ${1} | tr [[:upper:]] [[:lower:]])
MACADD=$(echo ${2} | tr [[:upper:]] [[:lower:]])
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35059710
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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