It still doesn't work for me for some reason.
Code:
#! /bin/sh Code:
[root@c-des-main1-rec standard_scripts]# . ./mknasosnames2.sh |
It seems to be cutting off the name:
No such file or directoryng_Systems/linux/types.sdr Which OS is this? Maybe you need to use a newer shell like bash for the script? |
Quote:
|
Quote:
$(<afile); is improper use of < :) + !!!FOR IN LOOP!!! problem lies in IN instruction that read array separated by spaces!!! remember FOR is just cycle construct not some evil overbuggy lib :) you can do stupid mistakes with while loop too :) most efficient / right path is place for competition.. but i don't want to write in bash sub program to read bytes in cache then determine end-line characters. PS: thanks for read -r :) my man is a little bit messed up with C header functions.. readarray all that i quick found upto job specs working good. hmm strange it's not part of coreutils .. also lines in bash man page help make doubts about using it on large files. Quote:
|
I ran dos2unix on those files and now it works! Now to finish the rest of the code.
|
Quote:
|
1)wineconsole cmd
2)DOSBOX |
Quote:
The main issue I have with it is that proper use of it relies on shell word splitting, which means that the coder must know in advance that the file is in the proper format, and will generate exactly the list of word tokens necessary for the loop. One small mistake there and you have errors. The second issue is, indeed, with inefficiency and the possibility of hitting the ARG_MAX limit of your system. I consider this a secondary problem, as this unlikely to be a hard limit in most scripts. Still, there is potential for it. In any case, it's much better in the long run to just do it the right way all the time, and use a proper while+read loop. With practice and experience it's no more difficult to write one of those than a for loop; and it's much safer, flexible, and efficient in all situations. In any case, calling it a "sub program" is a serious misnomer. It's just another type of loop, not any more complex to set up than any other. Finally, and most importantly here, while you are certainly free to do whatever you want in your own private coding, when you're giving advice in a help forum like this it's your responsibility to always give the best advice you are capable of. That means attempting to show others correct practice, and not your lazy shortcuts (although certainly ignorance of correct practice is forgivable). That's why I harp on such things so often. I consider it a duty to educate and to weed out poor scripting practice whenever I can. There are generally very good reasons why experienced coders always tend to advise the use of or avoidance of certain structures, and you ignore their hard-earned experience at your peril. PS: "$( <file )" is simply a bash built-in convenience feature that behaves in exactly the same manner as "$( cat <file )". It only works inside command substitution brackets, and is certainly not portable. readarray (a.k.a. mapfile, apparently the proper name) is also a bash built-in keyword, as it has to be in order to set environment values directly. So no, you'll never find it in the coreutils. It's only function is to safely load an array with lines from a file, so as with any other variable usage, the limit is in the amount of RAM you have available in which to store the text. As long as you know you can stay inside that limit, it's certainly a viable alternative to a while loop. |
hey i just posted mistakes that i found in that article.
< is stdio input redirection which is not cat :) so construct $(< ) is illogical(call/fork shell with just input from file? try using just <filename in shell not like cat result?:)).(and tend to have some hidden caveats(like double input,special chars,etc....) found some when i searched correct instructions for file read). I can't and I won't do all work for poster... i shared exp and some quick search data that in my tests(yes i wrote mini tests for this specific scenario) made usable expected result). Each specific task have not so many best approaches and big a number of still useful. I made working suggestion in given(!) task params. You frame me that it's my lazy shortcuts? you make me smile:) Also don't push on while loop you sound like religion priest, let's not start flame wars. In bare bones this is just same loops with almost identical code(for with read -a ? not a problem :)). However i can understand you if you say read -a is a good way to read files... despite time out's i mentioned(and yet untested memory usage) it's a challenge to find another std useful file read line tool/command usable in shell... my search ended with readarray (but i tested shells stdio redirection,for in,cat's keys scenarios which not produced useful results.. ).. i hope we not hijacking this thread too much. |
What happens if you use a mkdir -p instead of a simple mkdir?
|
Quote:
Any other attempt at raw redirection (unassociated with a command) will fail, just as you expect. Quote:
Whatever you use yourself in private is your own business, and you will accept the consequences of those choices until such time as you learn better. But I will do what I can to ensure that the new, inexperienced scripters who come here to learn do not get taught to use and perpetuate those same errors. Quote:
|
Quote:
--- rod. |
Sorry that took so long, but I needed then to finish coding the rest of it, and it was not possible to entirely test everything, without first finishing a draft of the scripts so that everything is coded.
Code:
#! /bin/sh From here on out, I can assume that the standard scripts will always be stored in /standard_scripts. Here is the code that's giving me trouble now: mknasosnames: Code:
#! /bin/sh Code:
[root@c-des-main1-rec standard_scripts]# . ./mknasosnames.sh |
In post #12, above, you state that /etc/settings/Operating_Systems/linux/Mandriva.sdr contains
Quote:
By the way, I notice that your code often uses commands (like, e.g., mkdir) but hardly ever follows the command with a [ $? -ne 0 ] && echo "Could not ..." assert check. You might find the information about the bash built in trap function of interest. Also, I find your use of the pushd and popd built in functions somewhat inconsistent. Why not use them everywhere you now use a cd command? Or, if you're simply using the pushd command as a placeholder for the current directory, you could just do a variable_name="$(cwd)" and, to return there, a cd "${variable_name}". Of course, you might need the quotes if you directory names sometimes include blanks, etc., but that not much of a hardship. |
Thanks for catching that. I'll work on fixing it. That means I may not be able to use the exact same syntax.
|
All times are GMT -5. The time now is 08:27 AM. |