Take notes on the command line: Difference between revisions

Content added Content deleted
(Added XPL0 example.)
m (syntax highlighting fixup automation)
Line 12: Line 12:
=={{header|11l}}==
=={{header|11l}}==


<lang 11l>:start:
<syntaxhighlight lang="11l">:start:
I :argv.len == 1
I :argv.len == 1
print(File(‘notes.txt’).read(), end' ‘’)
print(File(‘notes.txt’).read(), end' ‘’)
Line 18: Line 18:
V f = File(‘notes.txt’, ‘a’)
V f = File(‘notes.txt’, ‘a’)
f.write(Time().format("YYYY-MM-DD hh:mm:ss\n"))
f.write(Time().format("YYYY-MM-DD hh:mm:ss\n"))
f.write("\t"(:argv[1..].join(‘ ’))"\n")</lang>
f.write("\t"(:argv[1..].join(‘ ’))"\n")</syntaxhighlight>


=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
Line 24: Line 24:
This code assembles into a .COM file that runs under MS-DOS.
This code assembles into a .COM file that runs under MS-DOS.


<lang asm> bits 16
<syntaxhighlight lang="asm"> bits 16
cpu 8086
cpu 8086
;;; MS-DOS PSP locations
;;; MS-DOS PSP locations
Line 186: Line 186:
filnam: db 'NOTES.TXT',0 ; File name to use
filnam: db 'NOTES.TXT',0 ; File name to use
section .bss
section .bss
filebuf: resb BUFSZ ; 4K file buffer</lang>
filebuf: resb BUFSZ ; 4K file buffer</syntaxhighlight>


{{out}}
{{out}}
Line 213: Line 213:
{{works with|Ada 2005}}
{{works with|Ada 2005}}


<lang Ada>with Ada.Calendar.Formatting;
<syntaxhighlight lang="ada">with Ada.Calendar.Formatting;
with Ada.Characters.Latin_1;
with Ada.Characters.Latin_1;
with Ada.Command_Line;
with Ada.Command_Line;
Line 263: Line 263:
Ada.Text_IO.Close (File => Notes_File);
Ada.Text_IO.Close (File => Notes_File);
end if;
end if;
end Notes;</lang>
end Notes;</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>#! /usr/local/bin/aime -a
<syntaxhighlight lang="aime">#! /usr/local/bin/aime -a


if (argc() == 1) {
if (argc() == 1) {
Line 293: Line 293:


f.byte('\n');
f.byte('\n');
}</lang>
}</syntaxhighlight>


=={{header|APL}}==
=={{header|APL}}==
{{works with|GNU APL}}
{{works with|GNU APL}}


<lang APL>#!/usr/local/bin/apl -s --
<syntaxhighlight lang="apl">#!/usr/local/bin/apl -s --


∇r←ch Join ls ⍝ Join list of strings with character
∇r←ch Join ls ⍝ Join list of strings with character
Line 334: Line 334:


Notes
Notes
)OFF</lang>
)OFF</syntaxhighlight>


{{out}}
{{out}}
Line 360: Line 360:
=={{header|AppleScript}}==
=={{header|AppleScript}}==
Requires a modernish version of OS X (Lion or later) on which osascript works as a shebang interpreter.
Requires a modernish version of OS X (Lion or later) on which osascript works as a shebang interpreter.
<lang applescript>#!/usr/bin/osascript
<syntaxhighlight lang="applescript">#!/usr/bin/osascript


-- format a number as a string with leading zero if needed
-- format a number as a string with leading zero if needed
Line 442: Line 442:
end try
end try
end if
end if
end run</lang>
end run</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>notes: "notes.txt"
<syntaxhighlight lang="rebol">notes: "notes.txt"
if? empty? arg [
if? empty? arg [
if exists? notes -> print read notes
if exists? notes -> print read notes
Line 454: Line 454:
"\t" ++ (join.with:" " to [:string] arg) ++ "\n"
"\t" ++ (join.with:" " to [:string] arg) ++ "\n"
write.append notes output
write.append notes output
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 465: Line 465:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang autohotkey>Notes := "Notes.txt"
<syntaxhighlight lang="autohotkey">Notes := "Notes.txt"


If 0 = 0 ; no arguments
If 0 = 0 ; no arguments
Line 487: Line 487:
FileAppend, `r`n, %Notes%
FileAppend, `r`n, %Notes%


EOF:</lang>
EOF:</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TAKE_NOTES.AWK [notes ... ]
# syntax: GAWK -f TAKE_NOTES.AWK [notes ... ]
# examples:
# examples:
Line 515: Line 515:
printf("\n") >>log_name
printf("\n") >>log_name
}
}
</syntaxhighlight>
</lang>
{{out}} from the three example commands:
{{out}} from the three example commands:
<pre>
<pre>
Line 530: Line 530:
for this to work with older versions of QB.
for this to work with older versions of QB.


<lang qbasic>IF LEN(COMMAND$) THEN
<syntaxhighlight lang="qbasic">IF LEN(COMMAND$) THEN
OPEN "notes.txt" FOR APPEND AS 1
OPEN "notes.txt" FOR APPEND AS 1
PRINT #1, DATE$, TIME$
PRINT #1, DATE$, TIME$
Line 545: Line 545:
CLOSE
CLOSE
END IF
END IF
END IF</lang>
END IF</syntaxhighlight>


=={{header|Batch File}}==
=={{header|Batch File}}==
{{works with|Windows NT|4}}
{{works with|Windows NT|4}}
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
if %1@==@ (
if %1@==@ (
if exist notes.txt more notes.txt
if exist notes.txt more notes.txt
Line 555: Line 555:
)
)
echo %date% %time%:>>notes.txt
echo %date% %time%:>>notes.txt
echo %*>>notes.txt</lang>
echo %*>>notes.txt</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
This must be compiled to an EXE and run from the command prompt.
This must be compiled to an EXE and run from the command prompt.
<lang bbcbasic> REM!Exefile C:\NOTES.EXE, encrypt, console
<syntaxhighlight lang="bbcbasic"> REM!Exefile C:\NOTES.EXE, encrypt, console
REM!Embed
REM!Embed
LF = 10
LF = 10
Line 588: Line 588:
CLOSE #notes%
CLOSE #notes%
QUIT</lang>
QUIT</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <time.h>
#include <time.h>


Line 621: Line 621:
if (note) fclose(note);
if (note) fclose(note);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.IO;
using System.IO;
using System.Text;
using System.Text;
Line 656: Line 656:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <fstream>
<syntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <iostream>
#include <ctime>
#include <ctime>
Line 695: Line 695:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(ns rosettacode.notes
<syntaxhighlight lang="clojure">(ns rosettacode.notes
(:use [clojure.string :only [join]]))
(:use [clojure.string :only [join]]))


Line 710: Line 710:
(println (slurp "NOTES.txt"))))
(println (slurp "NOTES.txt"))))


(notes *command-line-args*)</lang>
(notes *command-line-args*)</syntaxhighlight>


{{out}}
{{out}}
Line 730: Line 730:


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>% This program uses the "get_argv" function that is supplied iwth
<syntaxhighlight lang="clu">% This program uses the "get_argv" function that is supplied iwth
% PCLU in "useful.lib".
% PCLU in "useful.lib".


Line 797: Line 797:
else add_note(note)
else add_note(note)
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>$ ls
<pre>$ ls
Line 819: Line 819:
=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. NOTES.
PROGRAM-ID. NOTES.


Line 896: Line 896:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>(defparameter *notes* "NOTES.TXT")
<syntaxhighlight lang="lisp">(defparameter *notes* "NOTES.TXT")


(defun format-date-time (stream)
(defun format-date-time (stream)
Line 920: Line 920:


(defun main ()
(defun main ()
(notes (uiop:command-line-arguments)))</lang>
(notes (uiop:command-line-arguments)))</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>void main(in string[] args) {
<syntaxhighlight lang="d">void main(in string[] args) {
import std.stdio, std.file, std.datetime, std.range;
import std.stdio, std.file, std.datetime, std.range;


Line 936: Line 936:
f.writefln("\t%-(%s %)", args.dropOne);
f.writefln("\t%-(%s %)", args.dropOne);
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>C:\>notes Permission to speak, sir!
<pre>C:\>notes Permission to speak, sir!
Line 950: Line 950:


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang delphi>program notes;
<syntaxhighlight lang="delphi">program notes;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 991: Line 991:
sw.Free;
sw.Free;
end;
end;
end.</lang>
end.</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==


<lang e>#!/usr/bin/env rune
<syntaxhighlight lang="e">#!/usr/bin/env rune


def f := <file:notes.txt>
def f := <file:notes.txt>
Line 1,011: Line 1,011:
w.close()
w.close()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
{{trans|Erlang}}
{{trans|Erlang}}
<lang elixir>defmodule Take_notes do
<syntaxhighlight lang="elixir">defmodule Take_notes do
@filename "NOTES.TXT"
@filename "NOTES.TXT"
Line 1,029: Line 1,029:
end
end


Take_notes.main(System.argv)</lang>
Take_notes.main(System.argv)</syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
#! /usr/bin/env escript
#! /usr/bin/env escript


Line 1,057: Line 1,057:
Existing_contents = file_contents(),
Existing_contents = file_contents(),
file:write_file( file(), [Existing_contents, Notes, "\n"] ).
file:write_file( file(), [Existing_contents, Notes, "\n"] ).
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang Euphoria>constant cmd = command_line()
<syntaxhighlight lang="euphoria">constant cmd = command_line()
constant filename = "notes.txt"
constant filename = "notes.txt"
integer fn
integer fn
Line 1,091: Line 1,091:
puts(fn,line)
puts(fn,line)
close(fn)
close(fn)
end if</lang>
end if</syntaxhighlight>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
<lang fsharp>open System;;
<syntaxhighlight lang="fsharp">open System;;
open System.IO;;
open System.IO;;


Line 1,116: Line 1,116:
| 0 -> show_notes()
| 0 -> show_notes()
| _ -> take_note <| String.concat " " args;
| _ -> take_note <| String.concat " " args;
0;;</lang>
0;;</syntaxhighlight>


Usage:
Usage:
Line 1,133: Line 1,133:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>#! /usr/bin/env factor
<syntaxhighlight lang="factor">#! /usr/bin/env factor
USING: kernel calendar calendar.format io io.encodings.utf8 io.files
USING: kernel calendar calendar.format io io.encodings.utf8 io.files
sequences command-line namespaces ;
sequences command-line namespaces ;
Line 1,145: Line 1,145:
print flush
print flush
] with-file-appender
] with-file-appender
] if-empty</lang>
] if-empty</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==


<lang fantom>
<syntaxhighlight lang="fantom">
class Notes
class Notes
{
{
Line 1,175: Line 1,175:
}
}
}
}
</syntaxhighlight>
</lang>


Sample:
Sample:
Line 1,195: Line 1,195:
The following is SwiftForth-specific, and runs in the Forth environment rather than as a standalone terminal application. Win32Forth only needs simple replacements of DATE and TIME . A Unix Forth would come closer to the 'commandline' requirement, as Windows Forths for whatever reason very eagerly discard the Windows console. Because this runs in the Forth environment, the otherwise acceptable application words are stuffed in a wordlist. Standard Forth doesn't have the notion of create-it-if-it-doesn't-exist, so OPEN just tries again with CREATE-FILE if OPEN-FILE fails.
The following is SwiftForth-specific, and runs in the Forth environment rather than as a standalone terminal application. Win32Forth only needs simple replacements of DATE and TIME . A Unix Forth would come closer to the 'commandline' requirement, as Windows Forths for whatever reason very eagerly discard the Windows console. Because this runs in the Forth environment, the otherwise acceptable application words are stuffed in a wordlist. Standard Forth doesn't have the notion of create-it-if-it-doesn't-exist, so OPEN just tries again with CREATE-FILE if OPEN-FILE fails.


<lang forth>vocabulary note-words
<syntaxhighlight lang="forth">vocabulary note-words
get-current also note-words definitions
get-current also note-words definitions


Line 1,238: Line 1,238:
open 0 parse dup if add-note
open 0 parse dup if add-note
else 2drop dump then close ;
else 2drop dump then close ;
previous</lang>
previous</syntaxhighlight>
The following is exactly the same program, but written in 4tH. 4tH has an I/O system which is different from ANS-Forth. The notes file is specified on the commandline.
The following is exactly the same program, but written in 4tH. 4tH has an I/O system which is different from ANS-Forth. The notes file is specified on the commandline.
<lang forth>\ -- notes.txt
<syntaxhighlight lang="forth">\ -- notes.txt
include lib/argopen.4th
include lib/argopen.4th
include lib/ansfacil.4th
include lib/ansfacil.4th
Line 1,268: Line 1,268:
refill drop 0 parse dup if add-note else 2drop dump then ;
refill drop 0 parse dup if add-note else 2drop dump then ;


note</lang>
note</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
<lang fortran>
<syntaxhighlight lang="fortran">
program notes
program notes
implicit none
implicit none
Line 1,301: Line 1,301:
endif
endif
end program notes
end program notes
</syntaxhighlight>
</lang>
{{out}}<pre>
{{out}}<pre>
2022-2-20T18:40:13
2022-2-20T18:40:13
Line 1,310: Line 1,310:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>If Len(Command) Then
<syntaxhighlight lang="freebasic">If Len(Command) Then
Open "notes.txt" For Append As #1
Open "notes.txt" For Append As #1
Print #1, Date, Time
Print #1, Date, Time
Line 1,329: Line 1,329:
End If
End If
Close #1
Close #1
Sleep</lang>
Sleep</syntaxhighlight>




=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>'Note that the 1st item in 'Args' is the file name as on the command line './CLIOnly.gambas'
<syntaxhighlight lang="gambas">'Note that the 1st item in 'Args' is the file name as on the command line './CLIOnly.gambas'


Public Sub Main()
Public Sub Main()
Line 1,355: Line 1,355:
Endif
Endif


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,365: Line 1,365:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,413: Line 1,413:
os.Exit(1)
os.Exit(1)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>def notes = new File('./notes.txt')
<syntaxhighlight lang="groovy">def notes = new File('./notes.txt')
if (args) {
if (args) {
notes << "${new Date().format('YYYY-MM-dd HH:mm:ss')}\t${args.join(' ')}\n"
notes << "${new Date().format('YYYY-MM-dd HH:mm:ss')}\t${args.join(' ')}\n"
Line 1,422: Line 1,422:
println notes.text
println notes.text
}
}
</syntaxhighlight>
</lang>


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import System.Environment (getArgs)
<syntaxhighlight lang="haskell">import System.Environment (getArgs)
import System.Time (getClockTime)
import System.Time (getClockTime)


Line 1,436: Line 1,436:
else
else
do ct <- getClockTime
do ct <- getClockTime
appendFile "notes.txt" $ show ct ++ "\n\t" ++ unwords args ++ "\n"</lang>
appendFile "notes.txt" $ show ct ++ "\n\t" ++ unwords args ++ "\n"</syntaxhighlight>


{{out}} after a few runs:
{{out}} after a few runs:
Line 1,447: Line 1,447:


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang HicEst>SYSTEM(RUN) ! start this script in RUN-mode
<syntaxhighlight lang="hicest">SYSTEM(RUN) ! start this script in RUN-mode


CHARACTER notes="Notes.txt", txt*1000
CHARACTER notes="Notes.txt", txt*1000
Line 1,466: Line 1,466:
ENDIF
ENDIF


ALARM(999) ! quit HicEst immediately</lang>
ALARM(999) ! quit HicEst immediately</syntaxhighlight>
<pre>Thu 2010-09-16 18:42:15
<pre>Thu 2010-09-16 18:42:15
This is line 1
This is line 1
Line 1,475: Line 1,475:
=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==


<syntaxhighlight lang="icon">
<lang Icon>
procedure write_out_notes (filename)
procedure write_out_notes (filename)
file := open (filename, "rt") | stop ("no notes file yet")
file := open (filename, "rt") | stop ("no notes file yet")
Line 1,496: Line 1,496:
else add_to_notes (notes_file, args)
else add_to_notes (notes_file, args)
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,516: Line 1,516:
=={{header|J}}==
=={{header|J}}==
'''Solution''':<br>
'''Solution''':<br>
<lang j>require 'files strings'
<syntaxhighlight lang="j">require 'files strings'


notes=: monad define
notes=: monad define
Line 1,528: Line 1,528:


notes 2}.ARGV
notes 2}.ARGV
exit 0</lang>
exit 0</syntaxhighlight>


Create a Shortcut called <tt>Notes</tt> that calls the script above using the Target:<br>
Create a Shortcut called <tt>Notes</tt> that calls the script above using the Target:<br>
Line 1,551: Line 1,551:


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.*;
<syntaxhighlight lang="java">import java.io.*;
import java.nio.channels.*;
import java.nio.channels.*;
import java.util.Date;
import java.util.Date;
Line 1,571: Line 1,571:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|JScript}}
{{works with|JScript}}
<lang javascript>var notes = 'NOTES.TXT';
<syntaxhighlight lang="javascript">var notes = 'NOTES.TXT';


var args = WScript.Arguments;
var args = WScript.Arguments;
Line 1,600: Line 1,600:
f.WriteLine();
f.WriteLine();
f.Close();
f.Close();
}</lang>
}</syntaxhighlight>
<pre>> del NOTES.TXT
<pre>> del NOTES.TXT
> cscript /nologo notes.js
> cscript /nologo notes.js
Line 1,609: Line 1,609:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Dates
<syntaxhighlight lang="julia">using Dates


const filename = "NOTES.TXT"
const filename = "NOTES.TXT"
Line 1,621: Line 1,621:
end
end
close(fp)
close(fp)
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.2.10
<syntaxhighlight lang="scala">// version 1.2.10


import java.io.File
import java.io.File
Line 1,643: Line 1,643:
f.appendText(notes)
f.appendText(notes)
}
}
}</lang>
}</syntaxhighlight>


Sample output:
Sample output:
Line 1,655: Line 1,655:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>#!/usr/bin/lasso9
<syntaxhighlight lang="lasso">#!/usr/bin/lasso9


local(
local(
Line 1,676: Line 1,676:
else
else
#notesfile -> exists ? stdout(#notesfile -> readstring)
#notesfile -> exists ? stdout(#notesfile -> readstring)
}</lang>
}</syntaxhighlight>


Called with:
Called with:
<lang Lasso>./notes "Rosetta was here" Räksmörgås
<syntaxhighlight lang="lasso">./notes "Rosetta was here" Räksmörgås
./notes First Second Last
./notes First Second Last
./notes
./notes
</syntaxhighlight>
</lang>
<pre>2013-11-15 11:43:08
<pre>2013-11-15 11:43:08
Rosetta was here, Räksmörgås
Rosetta was here, Räksmörgås
Line 1,690: Line 1,690:


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>filename = "NOTES.TXT"
<syntaxhighlight lang="lua">filename = "NOTES.TXT"


if #arg == 0 then
if #arg == 0 then
Line 1,710: Line 1,710:


fp:close()
fp:close()
end</lang>
end</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang>If[Length[$CommandLine < 11], str = OpenRead["NOTES.TXT"];
<syntaxhighlight lang="text">If[Length[$CommandLine < 11], str = OpenRead["NOTES.TXT"];
Print[ReadString[str, EndOfFile]]; Close[str],
Print[ReadString[str, EndOfFile]]; Close[str],
str = OpenAppend["NOTES.TXT"]; WriteLine[str, DateString[]];
str = OpenAppend["NOTES.TXT"]; WriteLine[str, DateString[]];
WriteLine[str, "\t" <> StringRiffle[$CommandLine[[11 ;;]]]];
WriteLine[str, "\t" <> StringRiffle[$CommandLine[[11 ;;]]]];
Close[str]]</lang>
Close[str]]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==


<lang Matlab> function notes(varargin)
<syntaxhighlight lang="matlab"> function notes(varargin)
% NOTES can be used for taking notes
% NOTES can be used for taking notes
% usage:
% usage:
Line 1,746: Line 1,746:
fprintf(fid,'\n');
fprintf(fid,'\n');
fclose(fid);
fclose(fid);
end; </lang>
end; </syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang mercury>:- module notes.
<syntaxhighlight lang="mercury">:- module notes.
:- interface.
:- interface.


Line 1,809: Line 1,809:
notes_filename = "NOTES.TXT".
notes_filename = "NOTES.TXT".


:- end_module notes.</lang>
:- end_module notes.</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import os, times, strutils
<syntaxhighlight lang="nim">import os, times, strutils


if paramCount() == 0:
if paramCount() == 0:
Line 1,821: Line 1,821:
f.writeLine getTime()
f.writeLine getTime()
f.writeLine "\t", commandLineParams().join(" ")
f.writeLine "\t", commandLineParams().join(" ")
f.close()</lang>
f.close()</syntaxhighlight>
Sample format.txt:
Sample format.txt:
<pre>2021-04-21T15:49:00+02:00
<pre>2021-04-21T15:49:00+02:00
Line 1,829: Line 1,829:


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>#! /usr/bin/env ocaml
<syntaxhighlight lang="ocaml">#! /usr/bin/env ocaml
#load "unix.cma"
#load "unix.cma"


Line 1,859: Line 1,859:
if Array.length Sys.argv = 1
if Array.length Sys.argv = 1
then dump_notes()
then dump_notes()
else take_notes()</lang>
else take_notes()</syntaxhighlight>


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>functor
<syntaxhighlight lang="oz">functor
import
import
Application
Application
Line 1,895: Line 1,895:
end
end
{Application.exit 0}
{Application.exit 0}
end</lang>
end</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Free Pascal in Delphi mode or Delphi in console mode.
Free Pascal in Delphi mode or Delphi in console mode.


<syntaxhighlight lang="pascal">
<lang Pascal>
{$mode delphi}
{$mode delphi}
PROGRAM notes;
PROGRAM notes;
Line 1,939: Line 1,939:
END;
END;
END.
END.
</syntaxhighlight>
</lang>


{{out|Program usage and output}}
{{out|Program usage and output}}
Line 1,954: Line 1,954:


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>my $file = 'notes.txt';
<syntaxhighlight lang="perl">my $file = 'notes.txt';
if ( @ARGV ) {
if ( @ARGV ) {
open NOTES, '>>', $file or die "Can't append to file $file: $!";
open NOTES, '>>', $file or die "Can't append to file $file: $!";
Line 1,962: Line 1,962:
print <NOTES>;
print <NOTES>;
}
}
close NOTES;</lang>
close NOTES;</syntaxhighlight>


{{out}} after a few runs:
{{out}} after a few runs:
Line 1,973: Line 1,973:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cmd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">(),</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cmd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">(),</span>
Line 1,986: Line 1,986:
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}==
=={{header|PHP}}==
<lang php>
<syntaxhighlight lang="php">
#!/usr/bin/php
#!/usr/bin/php
<?php
<?php
Line 2,000: Line 2,000:
else
else
@readfile('notes.txt');
@readfile('notes.txt');
</syntaxhighlight>
</lang>
Note that the error suppression operator (@) is considered bad coding practice.
Note that the error suppression operator (@) is considered bad coding practice.


Line 2,016: Line 2,016:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
<syntaxhighlight lang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l


(load "@lib/misc.l")
(load "@lib/misc.l")
Line 2,022: Line 2,022:
(out "+notes.txt" (prinl (stamp) "^J^I" (glue " " @)))
(out "+notes.txt" (prinl (stamp) "^J^I" (glue " " @)))
(and (info "notes.txt") (in "notes.txt" (echo))) )
(and (info "notes.txt") (in "notes.txt" (echo))) )
(bye)</lang>
(bye)</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang PL/I>NOTES: procedure (text) options (main); /* 8 April 2014 */
<syntaxhighlight lang="pl/i">NOTES: procedure (text) options (main); /* 8 April 2014 */
declare text character (100) varying;
declare text character (100) varying;
declare note_file file;
declare note_file file;
Line 2,061: Line 2,061:
put file (note_file) skip;
put file (note_file) skip;
put skip list ('The file, NOTES.TXT, has been created');
put skip list ('The file, NOTES.TXT, has been created');
end NOTES;</lang>
end NOTES;</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>$notes = "notes.txt"
<syntaxhighlight lang="powershell">$notes = "notes.txt"
if (($args).length -eq 0) {
if (($args).length -eq 0) {
if(Test-Path $notes) {
if(Test-Path $notes) {
Line 2,072: Line 2,072:
Get-Date | Add-Content $notes
Get-Date | Add-Content $notes
"`t" + $args -join " " | Add-Content $notes
"`t" + $args -join " " | Add-Content $notes
}</lang>
}</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>#FileName="notes.txt"
<syntaxhighlight lang="purebasic">#FileName="notes.txt"
Define argc=CountProgramParameters()
Define argc=CountProgramParameters()
If OpenConsole()
If OpenConsole()
Line 2,098: Line 2,098:
EndIf
EndIf
EndIf
EndIf
EndIf</lang>
EndIf</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import sys, datetime, shutil
<syntaxhighlight lang="python">import sys, datetime, shutil


if len(sys.argv) == 1:
if len(sys.argv) == 1:
Line 2,112: Line 2,112:
with open('notes.txt', 'a') as f:
with open('notes.txt', 'a') as f:
f.write(datetime.datetime.now().isoformat() + '\n')
f.write(datetime.datetime.now().isoformat() + '\n')
f.write("\t%s\n" % ' '.join(sys.argv[1:]))</lang>
f.write("\t%s\n" % ' '.join(sys.argv[1:]))</syntaxhighlight>


'''Sample notes.txt file'''
'''Sample notes.txt file'''
Line 2,123: Line 2,123:


=={{header|R}}==
=={{header|R}}==
<lang R>#!/usr/bin/env Rscript --default-packages=methods
<syntaxhighlight lang="r">#!/usr/bin/env Rscript --default-packages=methods


args <- commandArgs(trailingOnly=TRUE)
args <- commandArgs(trailingOnly=TRUE)
Line 2,134: Line 2,134:
cat(file=conn, date(), "\n\t", paste(args, collapse=" "), "\n", sep="")
cat(file=conn, date(), "\n\t", paste(args, collapse=" "), "\n", sep="")
}
}
close(conn)</lang>
close(conn)</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==


<syntaxhighlight lang="racket">
<lang Racket>
#!/usr/bin/env racket
#!/usr/bin/env racket
#lang racket
#lang racket
Line 2,153: Line 2,153:
(date->string (current-date) #t)
(date->string (current-date) #t)
(string-join notes))))))
(string-join notes))))))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)


<lang perl6>my $file = 'notes.txt';
<syntaxhighlight lang="raku" line>my $file = 'notes.txt';


multi MAIN() {
multi MAIN() {
Line 2,168: Line 2,168:
$fh.say: DateTime.now, "\n\t", @note;
$fh.say: DateTime.now, "\n\t", @note;
$fh.close;
$fh.close;
}</lang>
}</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>REBOL [
<syntaxhighlight lang="rebol">REBOL [
Title: "Notes"
Title: "Notes"
URL: http://rosettacode.org/wiki/Take_notes_on_the_command_line
URL: http://rosettacode.org/wiki/Take_notes_on_the_command_line
Line 2,182: Line 2,182:
] [
] [
write/binary/append notes rejoin [now lf tab args lf]
write/binary/append notes rejoin [now lf tab args lf]
]</lang>
]</syntaxhighlight>


{{out|Sample session}}
{{out|Sample session}}
Line 2,199: Line 2,199:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program implements the "NOTES" command (append text to a file from the C.L.).*/
<syntaxhighlight lang="rexx">/*REXX program implements the "NOTES" command (append text to a file from the C.L.).*/
timestamp=right(date(),11,0) time() date('W') /*create a (current) date & time stamp.*/
timestamp=right(date(),11,0) time() date('W') /*create a (current) date & time stamp.*/
nFID = 'NOTES.TXT' /*the fileID of the "notes" file. */
nFID = 'NOTES.TXT' /*the fileID of the "notes" file. */
Line 2,213: Line 2,213:
call lineout nFID,tab||arg(1) /* " " text " " " */
call lineout nFID,tab||arg(1) /* " " text " " " */
end
end
/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>notes = 'NOTES.TXT'
<syntaxhighlight lang="ruby">notes = 'NOTES.TXT'
if ARGV.empty?
if ARGV.empty?
File.copy_stream(notes, $stdout) rescue nil
File.copy_stream(notes, $stdout) rescue nil
else
else
File.open(notes, 'a') {|file| file.puts "%s\n\t%s" % [Time.now, ARGV.join(' ')]}
File.open(notes, 'a') {|file| file.puts "%s\n\t%s" % [Time.now, ARGV.join(' ')]}
end</lang>
end</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
This uses version 0.4 of the <code>chrono</code> crate
This uses version 0.4 of the <code>chrono</code> crate
<lang Rust>extern crate chrono;
<syntaxhighlight lang="rust">extern crate chrono;


use std::fs::OpenOptions;
use std::fs::OpenOptions;
Line 2,268: Line 2,268:
add_to_notes(&note.join(" ")).expect("failed to write to NOTES.TXT");
add_to_notes(&note.join(" ")).expect("failed to write to NOTES.TXT");
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}
{{libheader|Scala}}
<lang scala>import java.io.{ FileNotFoundException, FileOutputStream, PrintStream }
<syntaxhighlight lang="scala">import java.io.{ FileNotFoundException, FileOutputStream, PrintStream }
import java.time.LocalDateTime
import java.time.LocalDateTime


Line 2,290: Line 2,290:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
(moved from Racket)
(moved from Racket)
{{works with|Racket}}
{{works with|Racket}}
<lang scheme>#lang racket
<syntaxhighlight lang="scheme">#lang racket
(require racket/date)
(require racket/date)
(define *notes* "NOTES.TXT")
(define *notes* "NOTES.TXT")
Line 2,314: Line 2,314:
(fprintf fo "~a~n\t~a~n" dt ln)))
(fprintf fo "~a~n\t~a~n" dt ln)))
#:mode 'text #:exists 'append)
#:mode 'text #:exists 'append)
]))</lang>
]))</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
$ include "getf.s7i";
$ include "getf.s7i";
$ include "time.s7i";
$ include "time.s7i";
Line 2,339: Line 2,339:
end if;
end if;
end if;
end if;
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var file = %f'notes.txt'
<syntaxhighlight lang="ruby">var file = %f'notes.txt'


if (ARGV.len > 0) {
if (ARGV.len > 0) {
Line 2,351: Line 2,351:
var fh = file.open_r
var fh = file.open_r
fh && fh.each { .say }
fh && fh.each { .say }
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,365: Line 2,365:
=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
{{works with|Macro SNOBOL4 in C}}
{{works with|Macro SNOBOL4 in C}}
<lang snobol>#! /usr/local/bin/snobol4 -b
<syntaxhighlight lang="snobol">#! /usr/local/bin/snobol4 -b
a = 2 ;* skip '-b' parameter
a = 2 ;* skip '-b' parameter
notefile = "notes.txt"
notefile = "notes.txt"
Line 2,376: Line 2,376:
notes = date()
notes = date()
notes = char(9) args
notes = char(9) args
end</lang>
end</syntaxhighlight>


=={{header|Swift}}==
=={{header|Swift}}==
<lang Swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


let args = Process.arguments
let args = Process.arguments
Line 2,419: Line 2,419:


let strData = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let strData = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
handler?.writeData(strData!)</lang>
handler?.writeData(strData!)</syntaxhighlight>
{{out}}
{{out}}
Example output
Example output
Line 2,430: Line 2,430:


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl># Make it easier to change the name of the notes file
<syntaxhighlight lang="tcl"># Make it easier to change the name of the notes file
set notefile notes.txt
set notefile notes.txt


Line 2,446: Line 2,446:
close $f
close $f
}
}
}</lang>
}</syntaxhighlight>
{{out}} after a few runs:
{{out}} after a few runs:
<pre>
<pre>
Line 2,458: Line 2,458:
{{works with|R3}}
{{works with|R3}}
The lack of built-in high level time and date functions makes it more difficult than necessary, since they have to be implemented by user defined functions.
The lack of built-in high level time and date functions makes it more difficult than necessary, since they have to be implemented by user defined functions.
<lang>If Cmd (0) > 1 Then ' if there are commandline arguments
<syntaxhighlight lang="text">If Cmd (0) > 1 Then ' if there are commandline arguments
If Set (a, Open ("notes.txt", "a")) < 0 Then
If Set (a, Open ("notes.txt", "a")) < 0 Then
Print "Cannot write \qnotes.txt\q" ' open the file in "append" mode
Print "Cannot write \qnotes.txt\q" ' open the file in "append" mode
Line 2,517: Line 2,517:
_Format Param (2) : Return (Join (Iif (a@<10, Join(b@, "0"), b@), Str (a@)))
_Format Param (2) : Return (Join (Iif (a@<10, Join(b@, "0"), b@), Str (a@)))
_Monthdays Param (2) : Return (((a@ + (a@<7)) % 2) + 30 - ((2 - b@) * (a@=1)))
_Monthdays Param (2) : Return (((a@ + (a@<7)) % 2) + 30 - ((2 - b@) * (a@=1)))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>2022-04-02 14:58:57
<pre>2022-04-02 14:58:57
Line 2,528: Line 2,528:
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Bash version
Bash version
<lang bash>#
<syntaxhighlight lang="bash">#
NOTES=$HOME/notes.txt
NOTES=$HOME/notes.txt
if [[ $# -eq 0 ]] ; then
if [[ $# -eq 0 ]] ; then
Line 2,535: Line 2,535:
date >> $NOTES
date >> $NOTES
echo " $*" >> $NOTES
echo " $*" >> $NOTES
fi</lang>
fi</syntaxhighlight>


"Spoiled Bash kid" version
"Spoiled Bash kid" version
<lang bash>N=~/notes.txt;[[ $# -gt 0 ]] && { date ; echo " $*"; exit 0; } >> $N || [[ -r $N ]] && cat $N</lang>
<syntaxhighlight lang="bash">N=~/notes.txt;[[ $# -gt 0 ]] && { date ; echo " $*"; exit 0; } >> $N || [[ -r $N ]] && cat $N</syntaxhighlight>




Portable version
Portable version
<lang bash>NOTES=$HOME/notes.txt
<syntaxhighlight lang="bash">NOTES=$HOME/notes.txt
if test "x$*" = "x"
if test "x$*" = "x"
then
then
Line 2,552: Line 2,552:
date >> $NOTES
date >> $NOTES
echo " $*" >> $NOTES
echo " $*" >> $NOTES
fi</lang>
fi</syntaxhighlight>


{{omit from|Retro}}
{{omit from|Retro}}


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
<lang vbnet>Imports System.IO
<syntaxhighlight lang="vbnet">Imports System.IO


Module Notes
Module Notes
Line 2,575: Line 2,575:
End Try
End Try
End Function
End Function
End Module</lang>
End Module</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 2,582: Line 2,582:
An awkward task for Wren-cli which currently has no way of determining the current date and time.
An awkward task for Wren-cli which currently has no way of determining the current date and time.
We therefore have to ask the user to input it plus the note(s).
We therefore have to ask the user to input it plus the note(s).
<lang ecmascript>import "os" for Process
<syntaxhighlight lang="ecmascript">import "os" for Process
import "/ioutil" for File, FileUtil
import "/ioutil" for File, FileUtil
import "/date" for Date
import "/date" for Date
Line 2,597: Line 2,597:
var note = "\t" + args[1..-1].join(" ") + "\n"
var note = "\t" + args[1..-1].join(" ") + "\n"
FileUtil.append("NOTES.TXT", dateTime.format(dateFormatOut) + "\n" + note)
FileUtil.append("NOTES.TXT", dateTime.format(dateFormatOut) + "\n" + note)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,613: Line 2,613:
=={{header|XPL0}}==
=={{header|XPL0}}==
Checks for unlikely array overflows have been omitted for simplicity.
Checks for unlikely array overflows have been omitted for simplicity.
<lang XPL0>include xpllib; \Date and Time routines
<syntaxhighlight lang="xpl0">include xpllib; \Date and Time routines
int I, NotesSize, Ch, CmdArgSize;
int I, NotesSize, Ch, CmdArgSize;
char Notes(1_000_000), CmdArg(1000);
char Notes(1_000_000), CmdArg(1000);
Line 2,647: Line 2,647:
Close(3);
Close(3);
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 2,661: Line 2,661:
=={{header|zkl}}==
=={{header|zkl}}==
File notes.zkl:
File notes.zkl:
<lang zkl>const notesName="NOTES.TXT";
<syntaxhighlight lang="zkl">const notesName="NOTES.TXT";
args:=vm.arglist;
args:=vm.arglist;
if (not args)
if (not args)
Line 2,669: Line 2,669:
f.writeln(Time.Date.ctime(),"\n\t",args.concat(" "));
f.writeln(Time.Date.ctime(),"\n\t",args.concat(" "));
f.close();
f.close();
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>