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.
Again. The part between colons must resolve to a number.
Code:
z="abcd"; a="d"
echo ${z:${z%%$a*}0:-1}
This is what happens here
1. ${z%%$a*} resolves to abc;
2. Bash takes abc as the name of a (numeric) variable;
3. If this variable is not defined (unset), it will expand to zero according to the shell arithmetic rules;
4. The result will be abc.
I already knew it is similar in the prinziep with many programming languages with the length limit, would of course fit better here.
Code:
z[@]
echo ${z:0:${z%%$a*}[@]-1} Fieldindex Error
This was just an example, I do not understand how the variable can be replaced at the beginning by the result and the curly brace can be defined in a curly bracket.
That's just an example, I don't understand how the variable at the beginning can be exchanged for the result and code in the curly brace can be defined inside a curly brace.
How can I integrate the first fragment of code into the second one without going through the variable specification?
If it's impossible, there is no length limit imposed by numbers can be defined?
Code:
y=${z%%$a*}
echo ${y:0:-1}
unplace to
${${z%%$a*}:0:-1}
or
${z%%$a*:0:-1}
or
${(${z%%$a*}):0:-1}
Last edited by blumenwesen; 01-22-2022 at 11:13 AM.
Variable definition if not absolutely necessary often leads to it becoming confusing and it takes up memory, if several processes are to run a program as a starter and service, it can be a little more code and longer with old pcs.
Then, by combining code fragments in curly brackets, can also understand connections and syntax.
Variable definition if not absolutely necessary often leads to it becoming confusing and it takes up memory, if several processes are to run a program as a starter and service, it can be a little more code and longer with old pcs.
Then, by combining code fragments in curly brackets, can also understand connections and syntax.
No, that is just speculation. Writing unreadable code makes hard to understand/maintain it. Usually an additional variable has no any cost in speed and memory usage (especially when it holds only a few bytes) or at least it is extremely hard to measure and demonstrate. And bash is actually a slow language, this kind of "improvement" is completely futile.
Understandability depends on the structure of the code, the used function and variable names, not on the number of lines and curly brackets. Also you may add comments if you wish to explain...
I can read it better that way, and write in python as a starter without a paging file is code that has to be written very laboriously because the different quotation marks and special characters have to be taken into account several times, the python code is also more than double so long and taking longer to run because of the loading of the additional libraries that bash has direct access to.
Python libraries are constantly changing and therefore custom code would need to be updated pointlessly over and over again, especially if you still use 2.7.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.