Search…
Introduction
What does DCli do?
Install DCli
Writing your first CLI app
Add DCli to your project
pub.dev
github
Dart basics
Dart lambda functions
Function Arguments
Futures
stdin/stdout/stderr a primer
Tour
Overview
Using DCli functions
User input
Displaying information
Managing Files And Directories
Environment variables
Calling apps
Command Line Arguments
Paths
Glob Expansion
Piping
Locking
Fetch
The evils of CD
Assets/Resources
Cross Platform
Elevated Privileges
Performance
Dependency Management
Dependency Management
Pubspec Managment
DCli Tools
DCli tools
Use a shebang #!
DCli Compile
DCli Clean
DCli Create
DCli Doctor
DCli Install
DCli Run
DCli Warmup
DCli Pack
Upgrade DCli
Internal Workings
Internal Workings
waitForEx
Contributing
References
Examples
Projects
Code
Articles
build CLI apps in dart - part 1
build CLI apps in dart - part 2
Dealing with permissions
Dart on Linux - the perfect CLI tooling
Improving your build environment
Olivier Revial - CLI apps made easy
Video: package of the week
Powered By
GitBook
Use a shebang #!
A Shebang is a special entry on the first line of your script that tells the OS which command interpreter to use to execute your script.
Shebangs are currently only supported on Linux and OSx.
By adding a Shebang to the start of you Dart script you can directly run a script from the cli.
Without a Shebang:
1
dart hello.dart
Copied!
With a Shebang:
1
./hello.dart
Copied!
It's a small difference but rather useful particularly if you are calling one script from another.
To use a shebang you must have activated the optional DCli command line tools.
You do NOT need the DCli tools if you just want to use the DCli API but they are required if you want to use the Shebang feature.
If you want to use the DCli tools you must first activate them.
1
dart pub global activate dcli
2
dcli
install
Copied!
So let's look at how hello.dart looks with a shebang added.
The Shebang #! must be the very first line!
1
#
!
/
usr
/
bin
/
env dcli
2
​
3
/// import DCli's global functions
4
import
'package:dcli/dcli.dart'
;
5
​
6
void
main
()
{
7
print
(
'Hello World'
);
8
}
Copied!
On Linux and OSX you must mark the file as executable for the Shebang to work.
Mark the file as executable:
1
chmod
+x hello.dart
Copied!
if you used the
dcli create <script>
command then DCli will have already set the execute permission on your script and added the shebang!
Now run the script from the cli:
1
cli
>
./hello.dart
2
Hello world
3
cli
>
Copied!
You're now officially in the land of DCli magic.
Faster you say?
Read the section on
compiling
your script to make it run even faster.
DCli Tools - Previous
DCli tools
Next - DCli Tools
DCli Compile
Last modified
7mo ago
Copy link