-1

I want to hide the output of a command in the shell, but I still want to use the output in a variable: I am using this:

recmake=$(type -t cmake)

But I don't want an output in the shell. Only in the variable.

How can I do this.

Nils

Andy K
  • 4,944
  • 10
  • 53
  • 82
Noim
  • 445
  • 1
  • 3
  • 20
  • 1
    Try that -> http://stackoverflow.com/questions/18062778/how-to-hide-command-output-in-bash @nils-bergmann – Andy K May 01 '16 at 10:15
  • If i would do this like in the post, he will also not save the output in the variable. – Noim May 01 '16 at 10:18
  • 2
    @NilsBergmann the example provided should not generate output except maybe on the standard error. could you elaborate and provide that output wich you would like to hide. – Jay jargot May 01 '16 at 14:14
  • It should hide every output. With `recmake=$(type -t cmake)` I only want to get the output from the command but the user should not see the output. – Noim May 01 '16 at 16:35
  • 2
    @NilsBergmann: But which output do you get when executing `recmake=$(type -t cmake)`? I don't get any output from it. So I don't really understand what you want to hide... – arne.z May 01 '16 at 18:07

2 Answers2

2

You could add your code recmake=$(type -t cmake) to your .bashrc file and then load the variables like this: source ~/.bashrc.

arne.z
  • 3,242
  • 3
  • 24
  • 46
  • 1
    Hi @洋葱头, the **rec=``cmdline```** is doing the same thing as the `$(cmdline)`... – Andy K May 01 '16 at 11:30
  • @AndyK, oh okay, I didn't know that. But what's the problem with `$(cmdline)` then? It doesn't print output to the shell, right? – arne.z May 01 '16 at 12:11
  • 1
    `OP` is unclear about what he wants. Probably, not have the output of his shell script is what he is looking at. Therefore the solution I gave him – Andy K May 01 '16 at 13:10
  • I only want to have one script. Nothing else. – Noim May 01 '16 at 16:34
0

Have you tried the following, put everything inside of a bash script,nameofyourscript, and run it?

#!/bin/sh
recmake=$(type -t cmake)
echo $recmake

Then you do chmod +x nameofyourscript and ./nameofyourscript

Andy K
  • 4,944
  • 10
  • 53
  • 82
  • 1
    Read the question carefully. The op says - `But I don't want an output in the shell. Only in the variable.` If this is not clear to you ask them to clarify. – sjsam May 01 '16 at 14:20
  • Hi @sjsam my solution e.g putting everything within a script and running it, will not give output in the shell to OP – Andy K May 01 '16 at 17:02
  • 1
    What difference would it make if you don't spawn a new shell? The op should rephrase the question so that it will make some sense. – sjsam May 02 '16 at 01:22