Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

echo, redirection and variable expansion

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
Dominique_71
Veteran
Veteran
User avatar
Posts: 1957
Joined: Wed Aug 17, 2005 1:01 pm
Location: Switzerland (Romandie)

echo, redirection and variable expansion

  • Quote

Post by Dominique_71 » Sat Dec 27, 2025 7:34 pm

Code: Select all

$ echo fvwm user dir is "${FVWM_USERDIR}"       
fvwm user dir is /home/dom/.fvwm-crystal
$ echo 'fvwm user dir is "${FVWM_USERDIR}"'                 
fvwm user dir is "${FVWM_USERDIR}"
$ echo 'fvwm user dir is "${FVWM_USERDIR}"' | sed 's:user::'
fvwm  dir is "${FVWM_USERDIR}"
$ echo fvwm user dir is "${FVWM_USERDIR}" | sed 's:dom::'
fvwm user dir is /home//.fvwm-crystal
$ echo 'fvwm user dir is "${FVWM_USERDIR}"' | echo

 $ echo fvwm user dir is "${FVWM_USERDIR}" | echo

The last 2 commands only returns a newline.
As man echo, and man builtin, say nothing about redirection with echo, I was waiting that echo will understand it and return some content in addition to the new line. I am a little bit puzzled here.
"Confirm You are a robot." - the singularity
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4693
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sat Dec 27, 2025 7:43 pm

echo doesn't do anything with stdin. I think you want to use cat instead, but that "useless use of cat" then. So just leave the trailing echo and the pipe out?
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
flexibeast
l33t
l33t
Posts: 682
Joined: Mon Apr 04, 2022 4:15 am
Location: Naarm/Melbourne, Australia
Contact:
Contact flexibeast
Website

  • Quote

Post by flexibeast » Sat Dec 27, 2025 10:45 pm

If you need to pass the output of a command to `echo` (or indeed, `printf`), you can put that command in a subshell, e.g.:

Code: Select all

echo $(echo 'something')
Whether a pipeline involves creating a subshell for each component of the pipeline is shell-specific. According to the bash(1) man page, Bash creates a subshell:
Each command in a multi-command pipeline, where pipes are created, is executed in a subshell, which is a separate process.
Dash doesn't, or at least that's how i read the following in the dash(1) man page:
Note that unlike some other shells, each process in the pipeline is a child of the invoking shell (unless it is a shell builtin, in which case it executes in the current shell – but any effect it has on the environment is wiped).
The zshall(1) man page implies that Zsh does:
If a pipeline is preceded by `coproc', it is executed as a coprocess; a two-way pipe is established between it and the parent shell.
When the option is not set, job information from the parent shell is saved for output within a subshell (for example, within a pipeline).
https://wiki.gentoo.org/wiki/User:Flexibeast
My most recent wiki contributions
Top
Dominique_71
Veteran
Veteran
User avatar
Posts: 1957
Joined: Wed Aug 17, 2005 1:01 pm
Location: Switzerland (Romandie)

  • Quote

Post by Dominique_71 » Sat Dec 27, 2025 11:09 pm

I will not use that into a script, I was just testing things around and surprised by the result.
"Confirm You are a robot." - the singularity
Top
Post Reply

4 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic