The GNU Bourne-Again SHell - Patches: patch #9723, Alias definitions not recognized...
You are not allowed to post comments on this tracker with your current authentication level.
patch #9723: Alias definitions not recognized in an if-block
Submitter: | Martin Anantharaman <manantharaman> | ||
Submitted: | Thu 15 Nov 2018 09:18:49 AM UTC | ||
Category: | None | Priority: | 5 - Normal |
Status: | Invalid | Privacy: | Public |
Assigned to: | None | Open/Closed: | Open |
Jump to the original submission
Fri 16 Nov 2018 04:04:23 PM UTC, comment #6: |
Martin Anantharaman <manantharaman> |
Fri 16 Nov 2018 02:27:56 PM UTC, comment #5: Well, there's the updated version. Maybe that will be better from your perspective:
|
Chet Ramey <chet> |
Fri 16 Nov 2018 01:15:07 PM UTC, comment #4: (Made the mistak eof just replyinf to the notification mail first)
|
Martin Anantharaman <manantharaman> |
Thu 15 Nov 2018 04:51:20 PM UTC, comment #3: Like this?
|
Chet Ramey <chet> |
Thu 15 Nov 2018 04:47:39 PM UTC, comment #2: Thanks for the explanation, I was assuming that the alias is "known" (and can be used) once it is parsed - ahead of code like functions using it - whereas I now understand that the alias needs to be executed before code using them is parsed. I had already segregated alias definitions to their own files (kind of like C-headers with definitions) and had meanwhile also sucessfully changed the logic of sourcing - I source conditionally but in a command list (like "[ "$lib" ] || source lib.sh") rather than in an if-block.
|
Martin Anantharaman <manantharaman> |
Thu 15 Nov 2018 04:10:37 PM UTC, comment #1: Aliases are expanded when a command is read and parsed, not when it is executed. A compound command like `if' or `while' is parsed completely before any of its commands are executed.
|
Chet Ramey <chet> |
Thu 15 Nov 2018 09:18:49 AM UTC, original submission:
In trying to use a popular C-idiom in a library of shell-script(lets) I conditionalized code on the file not already being sourced - and then found that function-definitions no longer recognized valid alias-definitions (coming from other files, but that is probably immaterial), despite doing "shopt -s expand_aliases" - in fact the alias no longer works there at all.
|
Martin Anantharaman <manantharaman> |
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 3 latest changes.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2018-11-15 | chet | Status | None | Invalid | |
2018-11-15 | manantharaman | Attached File | - | Added test-source-alias.sh, #45429 | |
Attached File | - | Added test-source-alias-aliases.sh, #45430 |
Powered by Savane 3.13-bb6a.
Corresponding source code
That's succinct and to the point. I would elaborate a bit more:
The rules concerning the definition and use of aliases are somewhat confusing. Essentially an alias command needs to have been executed before code using it is parsed. Further, keep in mind that bash always reads and parses at least one complete line of input (which may include several commands including alias commands), but also any number of lines that make up a compound command (including function-definitions), before executing any of the commands. Overlooking this will lead to "command not found" errors at points of use within a complex command even after the alias definition.