Skip to content

Instantly share code, notes, and snippets.

@dgibbs64
Created December 10, 2014 11:19
Show Gist options
  • Save dgibbs64/586776800a3e27a8f951 to your computer and use it in GitHub Desktop.
Save dgibbs64/586776800a3e27a8f951 to your computer and use it in GitHub Desktop.
Carriage Return Checker
#!/bin/bash
# Carriage Return Checker
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 101214
# Description: Checks if a carriage return is present in a variable
# Place Variable here
var=
echo ""
if [ -z "${var}" ]; then
echo -e "\e[0;31mERROR!\e[0;39m Variable is empty"
elif [[ ${var} =~ $'\r' ]]; then
echo "Variable: ${var}";
echo -e "Carriage return: \e[0;32mYES\e[0;39m";
echo "Command to remove: tr -d '\r'"
else
echo "Variable: ${var}";
echo -e "Carriage Return: \e[0;31mNO\e[0;39m"
fi
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment