# pkgs.writeShellScriptBin error: syntax error, unexpected '@'

**URL:** https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405
**Category:** Help
**Created:** [August 1, 2020, 2:59am UTC](https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405 "2020-08-01T02:59:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ldeck](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ldeck/32/6391_2.png) [@ldeck](https://discourse.nixos.org/u/ldeck)
#### Post date: [August 1, 2020, 2:59am UTC](https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405/1 "2020-08-01T02:59:36Z")

</div>

Hi all, I’ve written a short script derivation in my `~/.config/nixpkgs/config.nix` that nix doesn’t like the bash syntax of.

```auto
{
  ...
  packageOverrides = pkgs: with pkgs; rec {
    ...
    foosh = pkgs.writeShellScriptBin “foolish” ‘’
      function help { ... }
      items=( “$@“ )
      (for e in "${items[@]}"; do [["$e" =~ ^(--)?help$]] && exit 0; done; exit 1) && help
      ...
    ‘’;
    ...
    myPackges = buildEnv {
      name = “my-packages”;
      paths = [
        foosh
        ...
      ];
   ...
}

```

I’m getting the following error, however:

```auto
% nix-env -iA nixpkgs.myPackages
error: syntax error, unexpected '@', at /Users/ldeck/.config/nixpkgs/config.nix:32:26

```

It appears nix config doesn’t like some permissible bash syntax.  
What’s recommended for this situation?

---

<div class="post-metadata">

### Author: ![samueldr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/samueldr/32/6_2.png) [@samueldr](https://discourse.nixos.org/u/samueldr)
#### Post date: [August 1, 2020, 3:47am UTC](https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405/2 "2020-08-01T03:47:29Z")

</div>

There is some consideration to take when writing complex bash inside of Nix expressions. The antiquotation[1] syntax of Nix conflicts with bash’s expansions:

```nix
"${something}"

```

Between `${` and `}` is a Nix expression.

So the following:

```nix
"${somearray[@]}"

```

Between the antiquotation characters you have the Nix expression

```nix
somearray[@]

```

Which is not valid Nix (seen in Nix repl:)

```plaintext
nix-repl> somearray[@]
error: syntax error, unexpected '@', at (string):1:11

```

There is a way to escape antiquotations, from [the Nix manual](https://nixos.org/nix/manual/#idm140737322066176):

> [In strings delimited with double-quotes (") the] special characters `"` and `\` and the character sequence `${` must be escaped by prefixing them with a backslash ( `\` ). Newlines, carriage returns and tabs can be written as `\n` , `\r` and `\t` , respectively.

> Since `${` and `''` have special meaning in indented strings, you need a way to quote them. `$` can be escaped by prefixing it with `''` (that is, two single quotes), i.e., `''$` . `''` can be escaped by prefixing it with `'` , i.e., `'''` . `$` removes any special meaning from the following `$` . Linefeed, carriage-return and tab characters can be written as `''\n` , `''\r` , `''\t` , and `''\` escapes any other character.

The second quote is for when you use indented strings (those that start with two single-quotes), which applies to your current case.

* * *

1: What the heck is _antiquotation_? It’s basically what Nix calls what other languages often all _expansion_ or _interpolation_.

---

<div class="post-metadata">

### Author: ![ldeck](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ldeck/32/6391_2.png) [@ldeck](https://discourse.nixos.org/u/ldeck)
#### Post date: [August 1, 2020, 4:40am UTC](https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405/3 "2020-08-01T04:40:23Z")

</div>

Thanks @samueldr! That’s very helpful.

So to confirm, there is no such thing atm as a string literal (multi-line or not) that’s no interpolated, right?

---

<div class="post-metadata">

### Author: ![samueldr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/samueldr/32/6_2.png) [@samueldr](https://discourse.nixos.org/u/samueldr)
#### Post date: [August 1, 2020, 4:53am UTC](https://discourse.nixos.org/t/pkgs-writeshellscriptbin-error-syntax-error-unexpected/8405/4 "2020-08-01T04:53:54Z")

</div>

There are two string literals, and they both support antiquotation. So: yes.
