The way it is now is, it checks the length of the variable, but I want to change it so that it will check to see if the first character of the value of the variable is zero or not so that the user can input values like "06, 07, 08" instead of "6, 7, 8".
I am aware of ${variable:start}, ${variable:start:length}, but could i stick that in the if statement?
if [ ${DATE_dd}, ${DATE_dd:0:1} == 1 ]; ?
Because if I want to run DATE_dd=`date +%d` then on a day like today "01" it will fail to GREP the LS -AL command to today's date, since the ls -al displays the day as a single digit, without padded zeroes.
The Typeset -Z2 command you told me about works really great for the if statement I posted before, since now I don't even need the if statement. But later on in the script, I need to take the value of the day in that variable and run a GREP for "today's" files.
For example:
ls -al <path> | grep "$date_b $date_d"
This will retrieve all files/directories that were created "today" in this format:
"Jun 22" or "Jun 24"... However this command breaks for a day like today "Jun 01". It fails because ls -al returns a day value that looks like this "Jun 1" (double space between Jun and 1). Instead of a padded zero, it's just replaced with a space.
So my script failed to work today because it tried to grep "Jun 1" instead of "Jun 1" (double space between Jun and 1). Is there a way I can check to see if the `date +d` command gave me a padded zero or not? (Check the first character of the string to see if it's zero, and if so, replace with a space).
The script above only works for the days of the month that are between the 10th and the 31st, but fails for all values betwee 01 and 09.
I am working on a script to check the var on all of my systems. Can someone help me fix it to work better or give me suggestions.
#!/bin/ksh
IN=/path/to/list_of_workstations.txt
while read hostnames
do
if ping $hostnames 1 | grep alive > /dev/null
then
percent=`ssh -q... (3 Replies)
Hi,
I have a variable and to it always alphanumeric value will be assigned.
If the value has any special characters in it then in the if statement it should exit like below
if (value has any speacial character)
then
exit
else
....
fi
can any one suggest how to acheive this? (4 Replies)
Below is the abstract of the script which is working fine.
if ]
then
error_process "Invalid month format."
return 1
fi
I am doing validation for month and it errors if the value is > 12 or < 0. In addition, I want to add another condition to error if it... (2 Replies)
i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character.
consider a file test.txt,inside the file... (1 Reply)
how can i check whether variable contains only character from a-z or A-Z....if my variable contains any alpha numeric, numeric or any character with some special one i.e. *%&@! etcetera etcetera....then it should show me please enter only characters......
Let my variable
var1="abc77}|"
then... (9 Replies)
if $1 = "123x456", how can I test for the non-numeric character 'x' in that string. I've tried expr with "" but it did not find the x. Any ideas? Can this perhaps be done with sed?
Thanks. (2 Replies)
I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions? (7 Replies)