File tree Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ sidebar_position: 30
55
66This command is equivalent to ` run ` , but it changes the way Scala CLI parses options (used to configure the tool) and
77inputs (the sources of your project) in order to be compatible with ` shebang `  scripts.
8+ The command ` shebang `  also allows for executing script files that don't have any file extensions.
89
910Normally, inputs and ` scala-cli `  options can be mixed. Program arguments (to be passed to your app) have to be specified
1011after ` -- `  (double dash) separator.
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ println(args.size)
1919println(args.headOption)
2020``` 
2121
22- And it works almost  correctly. 
22+ And it works correctly: 
2323
2424<ChainedSnippets >
2525
4040
4141</ChainedSnippets >
4242
43- And it also works. 
43+ And it also works: 
4444
4545<ChainedSnippets >
4646
@@ -173,4 +173,61 @@ world: not found
173173world: not found 
174174--> 
175175
176+ </ChainedSnippets >
177+ 
178+ ### Script files' extensions  
179+ 
180+ When running the ` shebang `  subcommand, script files don't need the ` .sc `  extension,
181+ but they are then REQUIRED to start with a shebang line:
182+ 
183+ ``` scala  title=hello-with-shebang
184+ #!/usr/bin/env -S scala-cli shebang -S 3  
185+ 
186+ println(args.size)
187+ println(args.headOption)
188+ ``` 
189+ 
190+ <ChainedSnippets >
191+ 
192+ ``` bash 
193+ chmod +x hello-with-shebang
194+ ./hello-with-shebang Hello World
195+ ``` 
196+ 
197+ ``` text 
198+ 2 
199+ Some(Hello) 
200+ ``` 
201+ <!--  Expected:
202+ 2 
203+ Some(Hello) 
204+ --> 
205+ 
206+ </ChainedSnippets >
207+ 
208+ ``` scala  title=hello-no-shebang
209+ println(args.size)
210+ println(args.headOption)
211+ ``` 
212+ 
213+ <ChainedSnippets >
214+ 
215+ ``` bash 
216+ chmod +x hello-no-shebang
217+ ./hello-no-shebang Hello World
218+ ``` 
219+ 
220+ ``` text 
221+ hello-no-shebang does not contain shebang header 
222+ possible fixes: 
223+   Add '#!/usr/bin/env scala-cli shebang' to the top of the file 
224+   Add extension to the file's name e.q. '.sc' 
225+ ``` 
226+ <!--  Expected:
227+ hello-no-shebang does not contain shebang header 
228+ possible fixes: 
229+   Add '#!/usr/bin/env scala-cli shebang' to the top of the file 
230+   Add extension to the file's name e.q. '.sc' 
231+ --> 
232+ 
176233</ChainedSnippets >
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments