I’m a bit fed up with that lately all i’ve been writing strangely always begins with #!/bin/sh
. Those who know what this means are either totally sympathetic or totally confused. Those who don’t: i’ve been bash shell scripting the past day. Rather say the weekend. It was fun… as long as i could find the corresponding manuals without going back to the 179th page of the Google results, and everything worked as it should’ve. It’s not simple if it’s your first time coding shell without any proper education of it before. And somehow when they’d been teaching us that stuff whenever it did something strange, they just looked at it and responded with a shrug. Now that’s not exactly what’s useful when i can’t get a relatively simple script to work, as it turned out, because shell is extra-super sensitive to whitespace. If you want to assign value to a variable, it crashes if there’s any around the equation sign, but on the other hand, if you’re comparing values or variables (eg in an if
statement), there have to be spaces around the comparison operators. The single- and double-quotes (‘ and “) also function just as in php: if you try to get the value of a variable inside single quotes, that won’t work as you want, but it will with double quotes. The troublesome with this is that when you’re debugging the string it seems to be inserting the correct values…
And the other thing is, i don’t like how everything’s documented, or not. I usually think that if i can’t find a good manual in at most half an hour’s intense searching, then there’s no such thing, or at least it’s so well hidden that i won’t find it in years’ time. With php and C++ it’s not that difficult, because there are good resource sites (php.net and cplusplus.com), which are easy to find and even not-so-very-basic problems can be solved using them (in the case of php for sure, with the other one… well, that’s up to you to decide: upon encountering some unexpected behaviour from a built-in function in C++ that site couldn’t explain anything and once again i had to dive into the ocean of forum posts, out of which one in every hundred is useful usually).
Since i couldn’t find any answer to my remaining two questions, i’ll ask them here—as i’ve done before elsewhere, without any result. Here it goes:
- If i want a welcome script to run in the background and greet every new logged in user, is that only possible if i edit the system files (i may be wrong but it was something .profile, or something along that line), or could i do it elseways too? (Also, how can i check if a new user logs in?)
- How can i make
sed
only output the matches, and not also those which don’t match? (My code is:sed -n -r '\s/(\S+)(\s+kukac\s+|\s+at\s+|_nospam_)([a-z0-9]([a-z0-9-.]*[a-z0-9])?)(.|\s+pont\s+|\s+dot\s+)([a-z]+|xn--[a-z0-9]+)/1@3.6n/pg' $file
But it’s not working as expected. Though it replaces all the concealed e-mail addresses with their normal forms, it also outputs the unmatched part of it. There can be multiple matches in a line.)