ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You can use the date program to do simple date parsing for you.
Shell scripting is great for gluing programs together, and providing flow control, but it's no substitute for a more fully-featured language like Perl or Python if you want to do a lot of string processing.
You can use the date program to do simple date parsing for you.
Shell scripting is great for gluing programs together, and providing flow control, but it's no substitute for a more fully-featured language like Perl or Python if you want to do a lot of string processing.
Entirely accurate, but we should also point out that, annoying as it may be, bash does have a lot of programming syntax, and can do most "low-level" things that other programming languages do. Personally, I prefer higher level languages, like Perl, for scripting in, but maybe that's because I'm a programmer more than a system administrator.
Anyway, the "UTC" string is a fixed string, 3 characters followed by a space (4 characters total), so you can get it to work like this:
Code:
export DATE="UTC 123 456" # Using this string as an example
$ echo -e UTC${DATE:4}
UTC123 456
Of course, if the variable is ever something other then "TIMESYS = 'UTC ' / Time system (usually UTC)", the parsed output will be missing the 15th character.
(What cut is doing is selectively cutting out to stdout, the characters 1-14, then cutting out the characters 16 to the end of the line also to stdout. "Cut" is a bit of a misnamer, imho).
"Yes, there is always 'a way to do it.'" In fact, there are always several ways.
Where you get into trouble sometimes is when you glom-onto "the first approach that pops into your head" and try to run-with-it. Then you start hammering on the thing, trying to make it work or to do this-n-that, and eventually you do (of course) "make it work," and you maybe feel very proud of yourself for your accomplishment. Which is all (of course) "well and good, but..."
Always try to pull-back and "see the big picture." If there is "more than one way to do 'it'," what's the best way?
"The best way," of course, is to discover that what you're trying to do has already been done by someone else. It probably has.
"The next-best way" is to discover that most of what you're trying to do has already been done by someone else, and so all you need to do is to leverage what they've already done. The Perl programming-language is rather famous for that, but Unix/Linux environments offer you a suite of power-tools.
It gives me pause to say this, but the Unix world has been building and championing "power tools" for more than 35 years now. (Ahem.) One of the reasons why Unix/Linux is so darned important and so heavily used is becauseof this extremely rich library of software tools. Get to know (some of) what's out there.
Also consider their intended purpose. "BASH scripting" is really intended to be an extension to BASH... which is intended to be "a shell." In other words, the intent of BASH-scripting is really not "to be a general-purpose programming language." There's no need for it: BASH already allows a command-line program to be written in any scripting-language you please, through the #! "shebang" construct. Therefore, if you're "doing amazing and creative things with BASH scripting," you just might be "struggling to make a square-wheel roll in order to transport your vegetables to market, when an antimatter-transporter is located conveniently nearby..."
Last edited by sundialsvcs; 06-16-2008 at 10:38 PM.
"an antimatter-transporter"
Aahh, so that's where it all went ...
Physicists have often wondered why there's preponderance of matter in our section of the universe.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.