1

In home I have a project folder nomse/bin/main.dart. in terminal. If I use command like,

dart nomse/bin/main.dart 

I can run my app.

UPDATE-1: I need to add path to .profile so I can run my app without typing a path on terminal. (I know how to add path to .profile), just bear with me.

All I need is that (as an example because I don't know how to do it) I need to add the nomse/bin/main.dart in .profile and run like dart nomse.

I need to give a name to my path like nomse. So I can run like dart nomse. How do I do that?

UPDATE-2:

in .profile I add path as 
PATH="$HOME/.nomse/bin/main.dart:${PATH}"
export PATH

how can I give a name to my path so I can run on terminal like?

dart nomse
Nick
  • 113
  • thanks Afshin, my problem is I am new to .profile and .sh, I need to run my main.dart with a command like dart main.dart. So if I add path to .profile how the dart command will knows main.dart? should I give name, like typing a dart nomse? – Nick Apr 18 '19 at 05:02
  • OK, then your question is duplicated of https://askubuntu.com/q/427818/283843 – αғsнιη Apr 18 '19 at 05:38

2 Answers2

3

It is not clear from your post, whether you want to add PATH to the executable dart or to the parameter main.dart.

For the first one, just export the PATH.

For the later, do you want to execute like: dartparamter should get expanded to dart $HOME/.paramter/bin/main.dart? In that case you can write a small macro/function in your ~/.bashrc:

function mydart()
{
   nomse="$1"
   /path/to/dart "$HOME/.$nomse/bin/main.dart
}

Then on terminal call mydart nomse.

  • thanks Mike, I am new to scripts, path, .profile etc. I am guessing your answer will be close what I am looking for. In my update 2 I have main.dart file. Normaly in terminal to run the file I have to use dart /and/my/path/main.dart. Now I add my path into .profile. I need a name my path so I can run just typing dart nomse in terminal. ".nomse" is a folder in my Home. and inside I have another folder call bin and inside that I have a main.dart file. Where I should add the variable name? Is my .profile path is ok. If so, should I add the function to .bashrc as you wrote? – Nick Apr 18 '19 at 05:34
  • the /path/to/dart already in my path. so I try to use dart "$HOME/.$nomse/bin/main.dart and fail ?? – Nick Apr 18 '19 at 05:51
  • @Nick, what do you mean by dart "$HOME/.$nomse/bin/main.dart fails? DO you get command not found error? In any case, the variable $nomse is a local var to the function mydart. You have to add this function to ~/.bashrc. Please read the answer carefully. – Mike V.D.C. Apr 18 '19 at 06:43
2

Suppose your command dart lies in a folder /path/to/folder/containing/dart/command, then just add the following line to the bottom of your ~/.profile:

dir=/path/to/folder/containing/dart/command
if [ -d "$dir" ] ; then
  PATH="$PATH:$dir"
fi

In addition to this (or alternatively) you can add the following line to your ~/.bashrc:

export PATH="$PATH:/path/to/folder/containing/dart/command"

For your current session, you can run this command.

This will tell the system where the executable dart lies.Now you can call

dart /path/to/main.dart

from anywhere.

user5325
  • 428
  • 2
  • 12
  • thanks, but my problem is I don't want to use the path. If I add path to .profile like update the my question, I need to run on terminal like dart nomse, and it will run my app. my problem is I don't know how to give a name to my path in .profile – Nick Apr 18 '19 at 05:14