> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/cli/es/guias/secrets/current-shell.md).

# Usar secretos en el shell actual

Cargar secretos de su bóveda en la sesión actual de Bash o PowerShell con devo secret shell enter y restaurarla después con leave.

`devo secret run` da secretos a un solo comando. Cuando los necesita para varios comandos seguidos, en la misma sesión de Bash o PowerShell, use `devo secret shell enter`. Define variables de entorno en su shell actual, y `devo secret shell leave` las deja como estaban.

{% hint style="warning" %}
Después de `devo secret shell enter`, los valores están en texto sin formato en su sesión de shell. Cada programa que inicie desde esa sesión los hereda, y el historial de su shell, las transcripciones o las herramientas de depuración pueden exponerlos. El enmascaramiento no se aplica. Salga del ámbito en cuanto termine, y prefiera [devo secret run](/cli/es/guias/secrets/run-with-secrets.md) siempre que un solo comando baste.
{% endhint %}

## Cómo funciona

Un programa no puede cambiar el entorno del shell que lo inició. Por eso `devo secret shell enter` no define nada por sí mismo: imprime un script corto para su shell, con los valores dentro, y usted ejecuta ese script con `eval` (Bash) o `Invoke-Expression` (PowerShell). `--shell` indica qué tipo de script imprimir: `bash` o `pwsh`.

## Compruebe primero las referencias

`--check` ejecuta una lectura sin valor de cada referencia, sin leer ningún secreto y sin imprimir un script. Confirma la sintaxis y, para una referencia con nombre o en un perfil local, la bóveda y la entrada, pero no que el campo se pueda leer: en Devolutions Cloud y Devolutions Server, una referencia canónica no se busca. Necesita salida JSON:

```bash
devo secret shell enter --shell bash --env-ref DB_PASSWORD=<reference> --check --output json
```

## Entrar en el ámbito

Repita `--env-ref NAME=<reference>` para cada variable. Ejecute el script solo si el comando tuvo éxito.

{% tabs %}
{% tab title="Bash" %}

```bash
enter="$(devo secret shell enter --shell bash \
  --env-ref DB_USER=<username-reference> \
  --env-ref DB_PASSWORD=<password-reference>)" && eval "$enter"
unset enter
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
$enter = & devo secret shell enter --shell pwsh `
  --env-ref DB_USER=<username-reference> `
  --env-ref DB_PASSWORD=<password-reference> | Out-String
if ($LASTEXITCODE -eq 0) { Invoke-Expression $enter }
Remove-Variable enter
```

{% endtab %}
{% endtabs %}

Si una referencia no se puede leer, el comando no imprime nada en su salida estándar, informa el error y termina con un código distinto de cero: su shell queda sin cambios.

{% hint style="danger" %}
`eval` y `Invoke-Expression` ejecutan todo lo que reciben. Páseles solo la salida de un comando `devo secret shell enter` o `devo secret shell leave` que haya tenido éxito, y no mezcle nunca su salida de error con ella.
{% endhint %}

## Ver qué está cargado

```bash
devo secret shell status --shell bash --output json
```

El estado muestra si un ámbito está activo, cuántos ámbitos están anidados y los nombres de las variables definidas por el ámbito más reciente. Nunca muestra los valores y necesita una salida JSON.

## Salir del ámbito

{% tabs %}
{% tab title="Bash" %}

```bash
leave="$(devo secret shell leave --shell bash)" && eval "$leave"
unset leave
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
$leave = & devo secret shell leave --shell pwsh | Out-String
if ($LASTEXITCODE -eq 0) { Invoke-Expression $leave }
Remove-Variable leave
```

{% endtab %}
{% endtabs %}

Salir restaura cada variable como estaba antes de entrar: su valor anterior si lo tenía, o ninguna variable si no lo tenía.

## Anidar ámbitos

Puede entrar en un ámbito mientras otro está activo, por ejemplo para añadir un segundo conjunto de credenciales. Cada `devo secret shell leave` cierra solo el ámbito más reciente, así que sale en el orden inverso al de entrada.

## Bueno saberlo

* El script de Bash generado usa funciones de Bash, así que ejecútelo en Bash, no en otro shell POSIX. Para PowerShell, `--shell powershell` funciona igual que `--shell pwsh`.
* Ejecute `devo secret shell status` y `devo secret shell leave` con el mismo valor de `--shell` que usó para entrar.
* `devo secret shell enter` no lee su entorno ni los archivos `.env`: enumere cada variable con `--env-ref`.
* Las referencias se resuelven a través del contexto actual. Añada `--context <context-name>` para usar otro espacio de trabajo.

## Siguiente

* [What stays hidden, and what doesn't](/cli/es/guias/understand/security-model.md)
* [Run a command with its secrets](/cli/es/guias/secrets/run-with-secrets.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/cli/es/guias/secrets/current-shell.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
