You haven't said what shell you are using. If this is ksh or plain sh, then the test you are performing in your if statement is still not valid. The double [ and ] suggested are bash. You are saying something like "If the value of $DAYis not null (always true for your code) create or replace the file 15"
You have a redirector, > where you need an expression. Have a look at the manual page for test to see them all. I think you need:-
I have removed the quotes from $DAY so it is not necessarily a string to do a numeric comparison, but the issue now is that if $DAY is null or unset, the if statement is again invalid, so you need to be certain it is set to something.
[[ ]] and [ ] work similar, but the implementation is different.
The [ is a builtin command. In fact it is an alias of the test command. (When run as [ the last argument must be ]. Command arguments may be redirected with < and >, and that is what caused your problem. The redirection can be prevented by quoting "<"">" or \<\>, but the standard operators are -lt and -gt. As with all command arguments, you should use "quotes" to prevent word splitting and globbing.
The [[ ]] is a compound, built into the shell interpreter. Because it is not a command, its content can be freely designed, and in fact a < and > are valid integer comparators. And the values are not subject to globbing, and word splitting happens before variable substitution (i.e. you need to quote "two words" to be seen as one value but not $word even if it's value is "two words").
These 2 Users Gave Thanks to MadeInGermany For This Post:
I am new to Linux. Using latest version of Ubuntu.
I want to make a script that creates a 1GB file filled with zeros using dd and then formats the file as vfat with a label of "MYFILE".
If anyone can help me it would be appreciated. (1 Reply)
I have the following script
#!/bin/sh
Usage () {
echo "Usage: $0 <config_file>"
echo "Example: ./sftp_ondemand_daily.sh /export/data/mbsesb/config/ond
emand.cfg /export/data/mbsesb/config/filename.lst"
exit 1
}
if
then
Usage
fi
... (6 Replies)
I am new to Linux. Using latest version of Ubuntu.
I want to make a script that creates a 1GB file filled with zeros using dd and then formats the file as vfat with a label of "MYFILE".
If anyone can help me it would be appreciated. (9 Replies)
Hi,
I am trying to create a lock file with the following code but for some reason after file is created it has
wrong name "PASP?.lock??"
Please let us know how to get rid of these '??' from file name and from where they are coming?
#!/bin/ksh... (6 Replies)
I'm working on a project that requires me to compress then relocate directories to a different location based on their last date of modification. After running the script I check to see if it worked, and upon unzipping the tar.gz using I created everything that should be there is. I then performed... (4 Replies)
Hi All,
I have a script that does daily checks on my storage environment and is run from an AIX host.
The script currently works great but I have been changing and updating bits of it to make it easier for my lesser colleagues to understand :p
However now with the updates I have made I... (1 Reply)
I have a script that runs ditto for me, and occasionally (if I exit the script while ditto is running in the background) it will leave an empty file named 0 in the script's directory. The next time I run the script, it generates incorrect data because of this file. I know I can easily insert a... (1 Reply)
I have a script that runs ditto for me, and occasionally (if I exit the script while ditto is running in the background) it will leave an empty file named 0 in the script's directory. The next time I run the script, it generates incorrect data because of this file. I know I can easily insert a... (1 Reply)
Hi,
I'm trying to use sed within a shell script (bash, running ubuntu). The command works fine from the command line, but when I use it within the script, rather than creating a file with the name I've specified, it creates one that ends with a question mark '?' when you use ls, e.g.... (3 Replies)