Skip to content

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

command-substitution

What’s the right way to quote $(command $arg)?

August 11, 2022 by Magenaut

It’s high time to solve this conundrum that’s been bothering me for years…

Categories Q&A, Unix & Linux Tags bash, command-substitution, quoting Leave a comment

Why do newline characters get lost when using command substitution?

August 11, 2022 by Magenaut

The read utility shall read a single line from standard input.

Categories Q&A, Unix & Linux Tags command-substitution, newlines, shell Leave a comment

Where has the trailing newline char gone from my command substitution?

August 10, 2022 by Magenaut

The following code best describes the situation.  Why is the last line not outputting the trailing newline char?  Each line’s output is shown in the comment.  I’m using GNU bash, version 4.1.5

Categories Q&A, Unix & Linux Tags command-line, command-substitution, shell, text-processing Leave a comment

Do I need to quote command substitutions when assigning their output to a variable?

August 10, 2022 by Magenaut

DIRNAME=”$(dirname $FILE)” will not do what you want if $FILE contains whitespace or globbing characters [?*.

Categories Q&A, Unix & Linux Tags command-substitution, quoting, shell Leave a comment

Command substitution: splitting on newline but not space

August 9, 2022 by Magenaut

I know I can solve this problem several ways, but I’m wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it.

Categories Q&A, Unix & Linux Tags bash, command-substitution Leave a comment

Pipelined Sed does not work on found filename inside Bash command substitution when invoked from Find “-exec”

August 9, 2022 by Magenaut

./sample.txt Specimen_before.TXT ./sample.TXT Specimen_after.TXT

Categories Q&A, Unix & Linux Tags bash, command-substitution, pipe, sed Leave a comment

Can command substitution be nested in variable substitution?

August 9, 2022 by Magenaut

I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this.

Categories Q&A, Unix & Linux Tags bash, command-substitution, variable-substitution Leave a comment

How to preserve the newline character (n) when capture output of a command in a variable

August 8, 2022 by Magenaut

As a simple example, I have a bunch of source code files. I want to store the “head” command output to a variable for all these files.

Categories Q&A, Unix & Linux Tags bash, command-substitution, newlines, shell Leave a comment

When should one use $( ) in defining variables

August 8, 2022 by Magenaut

Some shell scripts I have come across use the following syntax when defining variables:

Categories Q&A, Unix & Linux Tags command-substitution, shell, variable Leave a comment

Behaviour of bash command substitution with command from string in variable

August 8, 2022 by Magenaut

There are seven kinds of expansion … The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and filename expansion

Categories Q&A, Unix & Linux Tags bash, command-line, command-substitution, variable-substitution Leave a comment
Older posts
Page1 Page2 Next →
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress