Qbiz22
Qbiz22

Reputation: 11

z shell issue, running an alias and getting this " zsh: parse error near `}' "

I'm trying to make an alias in z shell (5.5.1) that will write node.js server code to a file, app.js. When I run the alias I get this

"zsh: parse error near `}'"

I tried to escape the curly brackets, that didn't work. I've searched and searched but couldn't find anything to clarify what I am doing wrong.

alias srvr='echo const express = require("express");
const app = express();

app.use(express.static("public"));
app.use(express.static("vendors"));

 app.get("/", function (req, res) {
   res.sendFile(__dirname + "/index.html");
 });

 app.listen(3000, function () {
   console.log("Example app listening on port 3000!");
 });' > app.js

Upvotes: 0

Views: 1267

Answers (1)

chepner
chepner

Reputation: 531868

Nothing after the unquoted semicolon is treated as an argument to echo. You should not be using an alias for this anyway. Use a function instead.

srvr () {
    echo 'const express = require("express");
const app = express();

app.use(express.static("public"));
app.use(express.static("vendors"));

 app.get("/", function (req, res) {
   res.sendFile(__dirname + "/index.html");
 });

 app.listen(3000, function () {
   console.log("Example app listening on port 3000!");
 });' > app.js
}

Upvotes: 1

Related Questions