- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Filtering Output from Shell Commands in Makefiles
Learn how to effectively filter output from shell commands in Makefiles using `filter-out`, and avoid common pitfalls with effective solutions.
---
This video is based on the question https://stackoverflow.com/q/63248149/ asked by the user 'null' ( https://stackoverflow.com/u/3533419/ ) and on the answer https://stackoverflow.com/a/63251101/ provided by the user 'MadScientist' ( https://stackoverflow.com/u/939557/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: filter-out on shell output
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Filtering Output from Shell Commands in Makefiles: A Simple Guide
In the world of programming and scripting, using tools efficiently can significantly boost productivity and ease of management. One such tool that often requires fine-tuning is the Makefile—a crucial element used in many build tools to automate the compilation of code. A common challenge encountered is how to filter output from shell commands effectively when defining variables in a Makefile.
In this guide, we will explore a specific problem related to filtering directories and how to use the filter-out function correctly in a Makefile context.
Understanding the Problem
You have a directory containing multiple folders—let's say dir1, dir2, dir3, and dir4. The goal is to process these directory names so that you can work with them by excluding certain directories using the filter-out function.
Here’s an outline of the original code snippet causing issues:
[[See Video to Reveal this Text or Code Snippet]]
When you run this code, the output correctly displays all directories:
[[See Video to Reveal this Text or Code Snippet]]
However, when you attempt to add the following lines to filter out certain directories (dir1 and dir3), you notice that the output remains unchanged:
[[See Video to Reveal this Text or Code Snippet]]
The result of the echo command still prints:
[[See Video to Reveal this Text or Code Snippet]]
Investigating the Issue
The core of the problem lies in the way the PARSE_MODULES function is evaluated. By using double dollar signs ($$), you're instructing Make to defer the execution of the command until the shell executes it, not during the actual evaluation of the Makefile.
Shell vs. Make Expansion
What this means is:
The MODULES variable ends up containing the shell script as a string rather than the evaluated output of running the command.
When you try to use the filter-out, it operates on text that doesn’t hold the expected directory names but rather the command itself.
A Simpler Approach
Instead of the convoluted method using shell commands, you can achieve similar results with far less complexity using built-in Make functions. Here's how:
[[See Video to Reveal this Text or Code Snippet]]
Breakdown of the Solution
Using wildcard: This built-in function retrieves a list of filenames or directories in a given path.
Using patsubst: This allows you to modify the file/directory names retrieved, formatting them as needed.
Using notdir: This simplifies the names by removing the directory part, leaving only the base names.
Using sort: Sorts the list of directories alphabetically.
Final Output
By using the restructured approach, when you filter out dir1 and dir3, you'd successfully get:
[[See Video to Reveal this Text or Code Snippet]]
Conclusion
In this guide, we explored how to successfully filter directory names from shell output in Makefiles using simpler approaches instead of convoluted shell scripts. Emphasizing the proper use of Make's built-in functions gives you clearer, cleaner, and more maintainable configurations.
By understanding the distinction between Make and shell script expansions, you can better harness Makefile capabilities for your projects. Happy coding!
Видео Filtering Output from Shell Commands in Makefiles канала vlogize
---
This video is based on the question https://stackoverflow.com/q/63248149/ asked by the user 'null' ( https://stackoverflow.com/u/3533419/ ) and on the answer https://stackoverflow.com/a/63251101/ provided by the user 'MadScientist' ( https://stackoverflow.com/u/939557/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: filter-out on shell output
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Filtering Output from Shell Commands in Makefiles: A Simple Guide
In the world of programming and scripting, using tools efficiently can significantly boost productivity and ease of management. One such tool that often requires fine-tuning is the Makefile—a crucial element used in many build tools to automate the compilation of code. A common challenge encountered is how to filter output from shell commands effectively when defining variables in a Makefile.
In this guide, we will explore a specific problem related to filtering directories and how to use the filter-out function correctly in a Makefile context.
Understanding the Problem
You have a directory containing multiple folders—let's say dir1, dir2, dir3, and dir4. The goal is to process these directory names so that you can work with them by excluding certain directories using the filter-out function.
Here’s an outline of the original code snippet causing issues:
[[See Video to Reveal this Text or Code Snippet]]
When you run this code, the output correctly displays all directories:
[[See Video to Reveal this Text or Code Snippet]]
However, when you attempt to add the following lines to filter out certain directories (dir1 and dir3), you notice that the output remains unchanged:
[[See Video to Reveal this Text or Code Snippet]]
The result of the echo command still prints:
[[See Video to Reveal this Text or Code Snippet]]
Investigating the Issue
The core of the problem lies in the way the PARSE_MODULES function is evaluated. By using double dollar signs ($$), you're instructing Make to defer the execution of the command until the shell executes it, not during the actual evaluation of the Makefile.
Shell vs. Make Expansion
What this means is:
The MODULES variable ends up containing the shell script as a string rather than the evaluated output of running the command.
When you try to use the filter-out, it operates on text that doesn’t hold the expected directory names but rather the command itself.
A Simpler Approach
Instead of the convoluted method using shell commands, you can achieve similar results with far less complexity using built-in Make functions. Here's how:
[[See Video to Reveal this Text or Code Snippet]]
Breakdown of the Solution
Using wildcard: This built-in function retrieves a list of filenames or directories in a given path.
Using patsubst: This allows you to modify the file/directory names retrieved, formatting them as needed.
Using notdir: This simplifies the names by removing the directory part, leaving only the base names.
Using sort: Sorts the list of directories alphabetically.
Final Output
By using the restructured approach, when you filter out dir1 and dir3, you'd successfully get:
[[See Video to Reveal this Text or Code Snippet]]
Conclusion
In this guide, we explored how to successfully filter directory names from shell output in Makefiles using simpler approaches instead of convoluted shell scripts. Emphasizing the proper use of Make's built-in functions gives you clearer, cleaner, and more maintainable configurations.
By understanding the distinction between Make and shell script expansions, you can better harness Makefile capabilities for your projects. Happy coding!
Видео Filtering Output from Shell Commands in Makefiles канала vlogize
Комментарии отсутствуют
Информация о видео
7 сентября 2025 г. 8:21:59
00:01:55
Другие видео канала





















