Ok, I just did something similar, I use different types of LS all the time at work to get lists of filenames.
I just recently did one that does an exclude, it worked when ran, so I saved it as a RUNTOREFRESH.sh and put it in crontab to run every hour on the 58th minute.
Now it worked when I ran it, but the script fails returning this error... RUNTOREFRESH.sh: 1: Syntax error: "(" unexpected
The script is... ls -RA1 !(Archive) > ./result.csv
It doesn't like the exclude, but I am unsure why. It accepts it if ran as a normal command directly.
I am obviously noob to scripting and really I just started doing some small stuff like file move's and listing > files because I was doing some much manually at work because no one knows anything about linux at all. If someone could give a quick reasoning as to why its failing as well I would really appreciate it.
I'm not quite sure what you are trying to exclude here. To ignore some files when using the "ls" command you need to use the -I switch (or --ignore=) and then provide the pattern that you wish to ignore.
I was told to use !(Directory|Filename.example|anotherexample.sh)
Go ahead and try it, it does work. If I run my statement normally in the terminal, it produces the results.csv file exactly as I wanted, with Archive folder excluded. However when I run as a script sh RUNTOREFRESH.sh I receive the above error... I will try it with --ignore, I was just wondering why it fails in a script but not directly input into the terminal and of course how to fix it.
Thanks for the reply let me play with the --ignore a sec...
Possibly the different way that bash and sh interpret regular expressions. I wasn't aware that !(xxx) worked in either of them (it sounds more like a C expression to me), but I'll take your word for it. I'd go for the ls facilities rather than rely upon shell expansion, which may differ between different shells.
Now it included implied characteristics like .: and on the folder ./ which I really didn't want because the info is copy and pasted. Now I thought the -A option removed implied characteristics. What am I missing?