> 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/it/guide/secrets/current-shell.md).

# Usare i segreti nella shell corrente

Caricare segreti dalla cassaforte nella sessione Bash o PowerShell corrente con devo secret shell enter, quindi ripristinarla con leave.

`devo secret run` dà i segreti a un solo comando. Quando ne ha bisogno per diversi comandi di seguito, nella stessa sessione Bash o PowerShell, usi `devo secret shell enter`. Imposta variabili d’ambiente nella shell corrente, e `devo secret shell leave` le riporta com’erano.

{% hint style="warning" %}
Dopo `devo secret shell enter`, i valori sono in testo in chiaro nella sessione della shell. Ogni programma che avvia da quella sessione li eredita, e la cronologia della shell, le trascrizioni o gli strumenti di debug possono esporli. Il mascheramento non si applica. Lasci l’ambito appena ha finito, e preferisca [devo secret run](/cli/it/guide/secrets/run-with-secrets.md) ogni volta che un solo comando basta.
{% endhint %}

## Come funziona

Un programma non può cambiare l’ambiente della shell che lo ha avviato. Quindi `devo secret shell enter` non imposta nulla da solo: stampa un breve script per la shell, con i valori al suo interno, e lei esegue quello script con `eval` (Bash) o `Invoke-Expression` (PowerShell). `--shell` indica quale tipo di script stampare: `bash` o `pwsh`.

## Verifichi prima i riferimenti

`--check` esegue una lettura senza valore di ogni riferimento, senza leggere alcun segreto e senza stampare uno script. Conferma la sintassi e, per un riferimento con nome o su un profilo locale, la cassaforte e la voce, ma non che il campo possa essere letto: su Devolutions Cloud e Devolutions Server un riferimento canonico non viene cercato. Richiede output JSON:

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

## Entrare nell’ambito

Ripeta `--env-ref NAME=<reference>` per ogni variabile. Esegua lo script solo se il comando è riuscito.

{% 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 %}

Se un riferimento non può essere letto, il comando non stampa nulla sul suo output standard, segnala l’errore e termina con un codice diverso da zero: la shell resta invariata.

{% hint style="danger" %}
`eval` e `Invoke-Expression` eseguono tutto ciò che ricevono. Passi loro solo l’output di un comando `devo secret shell enter` o `devo secret shell leave` riuscito e non mescoli mai il suo output di errore.
{% endhint %}

## Vedere che cosa è caricato

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

Lo stato mostra se un ambito è attivo, quanti ambiti sono annidati e i nomi delle variabili impostate dall’ambito più recente. Non mostra mai i valori e ha bisogno di un output JSON.

## Uscire dall’ambito

{% 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 %}

Uscire ripristina ogni variabile com’era prima di entrare: il suo valore precedente se ne aveva uno, oppure nessuna variabile se non ne aveva.

## Annidare gli ambiti

Può entrare in un ambito mentre un altro è attivo, per esempio per aggiungere un secondo insieme di credenziali. Ogni `devo secret shell leave` chiude solo l’ambito più recente, quindi esce nell’ordine inverso a quello di entrata.

## Buono a sapersi

* Lo script Bash generato usa funzionalità di Bash, quindi lo esegua in Bash, non in un’altra shell POSIX. Per PowerShell, `--shell powershell` funziona come `--shell pwsh`.
* Esegua `devo secret shell status` e `devo secret shell leave` con lo stesso valore `--shell` che ha usato per entrare.
* `devo secret shell enter` non legge l’ambiente né i file `.env`: elenchi ogni variabile con `--env-ref`.
* I riferimenti si risolvono tramite il contesto corrente. Aggiunga `--context <context-name>` per usare un altro spazio di lavoro.

## Successivo

* [What stays hidden, and what doesn't](/cli/it/guide/understand/security-model.md)
* [Run a command with its secrets](/cli/it/guide/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/it/guide/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.
