dsh 1.0.3 copy "dsh: ^1.0.3" to clipboard
dsh: ^1.0.3 copied to clipboard

Use shell scripts for automation in your favorite Dart, inspired by google/zx.

DSH: Dart Shell #

Use shell for automation in Dart, inspired by google/zx

Quick Start #

The simplest example:

import 'package:sh/sh.dart';

void main() {
  $('ls -l');
  $('echo hello');
}

Passing variables to the Shell:

import 'package:sh/sh.dart';

void main() {
  int num = 10;
  String dir = 'demo1';

  $('echo $num');
  $('mkdir -p $dir');
}

Executing Shell commands sequentially:

import 'package:sh/sh.dart';

void main() async {
  int a = 10;
  String dir = 'demo2';

  await $('echo $a');
  await $('mkdir -p $dir');
  await $('ls');
  await $('sleep 3');
}

Asynchronously executing multiple commands:

import 'package:sh/sh.dart';

void main() async {
  // Execute commands concurrently
  // Wait for all concurrent commands to complete
  await Future.wait([
    $('(sleep 1; echo 1)'),
    $('(sleep 2; echo 2)'),
    $('(sleep 3; echo 3)'),
    $('(sleep 4; echo 4)'),
    $('(sleep 5; echo 5)')
  ]);
}

Directly executing a Shell script:

import 'package:sh/sh.dart';

void main() {
  String dir = 'demo4';

  $('''
  cd $dir
  touch help.txt
  ls
  cd ..
  rm -rf $dir
  (sleep 1; echo 1)
  (sleep 2; echo 2)
  (sleep 3; echo 3)
  ''');
}
0
likes
160
pub points
0%
popularity

Publisher

verified publisherabandoft.com

Use shell scripts for automation in your favorite Dart, inspired by google/zx.

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

More

Packages that depend on dsh