乐闻世界logo
搜索文章和话题

How do I invoke deno from a shell script?

1个答案

1

Calling Deno from a shell script is actually very straightforward. First, ensure Deno is installed on your system. The installation process can be found in detail on the official Deno website Deno Official Website.

Installing Deno

For Linux or macOS systems, you can use the following simple command:

bash
curl -fsSL https://deno.land/x/install/install.sh | sh

For Windows, use PowerShell:

powershell
iwr https://deno.land/x/install/install.ps1 -useb | iex

Calling Deno from a Shell Script

Assuming Deno is already installed, you can call it from a shell script to run a Deno program. First, create a simple Deno script. For example, create a new file hello.ts with the following content:

typescript
console.log("Hello from Deno!");

Next, create a shell script to run this Deno script. Create a file named run_deno.sh with the following content:

bash
#!/bin/bash # Run the Deno program deno run hello.ts

Ensure your shell script has executable permissions. You can grant execution permissions with the following command:

bash
chmod +x run_deno.sh

Finally, you can run this script in the terminal to execute your Deno program:

bash
./run_deno.sh

This will output:

shell
Hello from Deno!

Summary

The process of calling Deno from a shell script includes:

  1. Ensure Deno is installed on your system.
  2. Write the Deno program.
  3. Create a shell script to call the deno run command to execute the Deno program.
  4. Set executable permissions for the shell script.
  5. Run the script.

This approach is ideal for automation scripts and tasks, allowing Deno-developed programs to integrate seamlessly into larger system environments.

2024年8月8日 03:14 回复

你的答案