Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linux bash script to change argument to lowercase

Posted on 2011-03-07
3
Medium Priority
?
498 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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