0

Suppose I have a js file (which can be executed using node):

process.stdout.write('Test')

Is there any way I can use this in a bash file? For example, to set the PS1?

Here is what I tried:

#!/usr/bin/env bash

get_output() {
    return node path/to/file.js
}


export PS1='$ $get_output >'

I'm pretty sure this shows you I am a bash newbie...

  • 1
    Does this answer your question? [BASH print result of linux command in PS1 variable](https://stackoverflow.com/questions/60000157/bash-print-result-of-linux-command-in-ps1-variable) – dibery Jun 14 '21 at 05:26
  • @Siddhart : See the section titled _Command Substitution_ in the bash man page. BTW. it is quite uncommon to put `PS1` into the environment. Are you sure that this is what you want? – user1934428 Jun 14 '21 at 06:00
  • The PS1 is just an example, but I might use it sometime ;) – Siddharth Shyniben Jun 14 '21 at 07:09

1 Answers1

1

You can take the output of a command using the $ parens operator.

export PS1=$(node path/to/file.js)
thanatonian2311
  • 331
  • 2
  • 11