The Shell

The PTSource Shell is a Unix-compatible environment that runs natively on Microsoft Windows. Its goal is to allow programs of Unix-like systems to be recompiled and run natively on Windows with minimal source code modifications by providing them with the same underlying API they would expect in those systems.

The PTSource Shell installation directory behaves like the root and follows a similar directory layout to that found in Unix-like systems, with familiar directories like /bin, /home, /etc, /usr, /var available within it, and includes by default hundreds of programs and command-line tools commonly found in the Unix world.

The PTSource Shell provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. Thus it is possible to launch Windows applications from the PTSource Shell environment, as well as to use PTSource Shell tools and applications within the Windows operating context.

Using the Shell

A non-quoted backslash \ is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline. If a \newline pair appears, and the backslash itself is not quoted, the \newline is treated as a line continuation (that is, it is removed from the input stream and effectively ignored). So moving in dirs in the Shell its slightly different so if you want to walk thru dirs you shoud use / instead of \ as in *nix.

Example

cd c:\   
# This is wrong and it will return c:
cd c:/   
# This is right and it will return c:\
cd c:\\
# This is also right and it will return c:\

Development Environment

The Shell as MinGW-w64 and Harbour already configured to build for Win32 and Win64.

Standard make commands :
  • make (standard *nix make)
  • ptsmake32 (Harbour make for x86)
  • ptsmake64 (Harbour make for x64)
  • tcc32 (TCC make for x86)
  • tcc64 (TCC make for x64)
  • makefasm (FASM for x86 and x64)
  • makensis (Generates installer from NSI)
BashRC and aliases

The Shell uses a simple ini file called PTShell.ini in the PTSource directory as its RC startup it fully supports aliases and it reads by default as fallows :

alias vi='nano'
alias vim='nano'
alias edit='nano'
alias joe='nano'
alias h='history'
alias mc='gmc'
alias nc='gmc'
alias d='dir'
alias more='less'
alias ls='ls --color'
alias l='ls -l '
alias back='cd $OLDPWD'
alias texclean='rm -f *.toc *.aux *.log *.cp *.fn *.tp *.vr *.pg *.ky'
alias php='phpc'
alias curl='curl -k'
EDITOR='nano'
FCEDIT='nano'
BASH='bash'
SHELL='bash'
CC='gcc'
TERM=vt100
HOME=C:\\PTSOURCE\\Platform\\PTEditor\\home
HISTFILE=C:\\PTSOURCE\\Platform\\PTEditor\\home\\bash_history
HISTSIZE=200
HISTFILESIZE=200
PATH1=C:\\PTSOURCE\\Platform\\PTEditor\\bin
#x86 MinGW and Harbour
PATH2=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\mingw32\\bin
PATH3=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\harbour32\\bin
#x64 MinGW and Harbour
#PATH2=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\mingw64\\bin
#PATH3=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\harbour64\\bin
PATH4=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\fasm32_64
PATH5=C:\\PTSOURCE\\Platform\\PTEditor\\bin\\python
PATH6=C:\\PTSOURCE\\Platform\\PTEditor\\bin\\nsis
PATH=$PATH1:$PATH2:$PATH3:$PATH4:$PATH5:$PATH6
MANPATH=C:\\PTSOURCE\\Platform\\PTEditor\\man
SAMPLES=C:\\PTSOURCE\\Platform\\PTEditor\\samples
FASMINC=C:\\PTSOURCE\\Platform\\PTEditor\\builder\\comp\\fasm32_64\\INCLUDE
export HOME PATH HISTFILE HISTSIZE HISTFILESIZE MANPATH EDITOR SHELL TERM BASH SAMPLES CC FASMINC
LOGIN_SHELL=true
cd $HOME

It can be edited to fit your needs.

Simple compilation commands examples from the Shell
  • gcc -c *.c && gcc *.o -o [binary file name]
  • make [clean|install]
  • ptsmake32 [*.prg|*.hbc]
  • ptsmake64 [*.prg|*.hbc]
Command line reference

basename - Display file namename

   usage: basename string [suffix]

    Display file name.  If suffix is supplied and matches the suffix on the
    filename, the suffix is stripped from the filename.


cat - Concatenate files

    usage: cat [-usvtenqbTB] files

    -q:	No error reports
    -u:	Unbuffered output
    -s: Strip multiple blank lines
    -v: Print control characters as ^X
    -t:	Print tabs as ^T
    -e: Print $ at end of line
    -n:	Print line number
    -b: Print block number
    -T: Force stdout into text mode (CR/LF translation)
    -B: Force stdout into binary mode (no CR/LF translation)

chmod - Change file attributes

    usage: chmod [-R] [absolute-mode | symbolic-mode | string-mode] files

    -R:	Recurse down directories

    symbolic mode

	 A symbolic mode has the form

	    [who] op permission [op permission ...]

	 The who value is any combination of the following:

	     u   Sets user permissions.
	     g   Sets group permissions.
	     o   Sets other permissions.
	     a   Sets all permissions; this is the default.

	 Group and Other permissions are mapped to user permissions on WIN.

	 The op value gives the action to take:

	     +   Turns on a permission.
	     -   Turns off a permission.
	     =   Turns on the specified permissions and turns off all others.

	 The permission value is any combination of the following:

	     r   Read permission.
	     x   Execute permission.  
	     w   Write permission.  
	     h   HIDDEN attribute. 
	     a   ARCHIVE attribute.  
	     s   Setuid/Setgid bit.
	     t   Text bit.

    absolute mode

	    A octal value made up using by ORing the following values.  Note
	    that some values may be invalid.

		4000   HIDDEN Attribute
		2000   SYSTEM Attribute
		1000   ARCHIVE Attribute
		0400   User read.
		0200   User write
		0100   User execute.
		0040   Group read.
		0020   Group write (mapped to user write attribute).
		0010   Group execute.
		0004   Other read.
		0002   Other write (mapped to user write attribute).
		0001   Other execute.

	    If the last character is a d (as in 001d), the absolute WIN
	    values listed below are assumed and no translation takes place.

	    001 - Read only
	    002 - Hidden
	    004 - system
	    040 - Archived

    string mode
	    A string matching the output long form for the mode from ls is
	    required (rxw------, for example).


cmp - Compare two files

    usage: cmp [-ls] file1 file2

    -l:	Report all differences
    -s: Silent mode.  exit code of 1 if there are differences


comm - select or reject lines common to two sorted files

    usage: comm [-[123]] file1 file2

    -1:		Reject column 1
    -2:		Reject column 2
    -3:		Reject column 3


cp - Copy files.

    usage: cp [-ipfCrRvn] f1 f2
	   cp [-ipfCrRvn] f1 ... fn d1
	   cp [-ipfCrRvn] d1 d2

    -i:	Ask before copying
    -r: Recurse down directories, copying tree to new location
    -R: Recurse down directories, copying tree to new location
    -v: verbose
    -n: show me what you're going to do, without doing it.
    -p: preserve access times
    -C: Convert sources files from WIN format to UNIX format
    -f: Force removal of destination files

csplit - Context or line file splitter
 
    usage: csplit [-s] [-k] [-nnumber] [-f prefix] file args ...

    -s:		Suppress printing of character counts
    -k:		Do not delete created files on error
    -f prefix	Prefix for created files (default: xx)
    -n number	Maximum number of files to create (default 99)


cut - Cut data out of a file


    usage: cut [ -f{args} [-s] [-d separator ] ] | [ -c{args} ] [filename [...]]
	   
    -f{args}:		Comma separated list of fields to extract
    -d separator:	Field separator (default tab)
    -s:			Skip lines with no fields
    -c{args}:		Comma separater list of columns to extract
    

date - Display / change date and time

    usage: date [-q] [+format] [[MMDDYY]hhmm[ss]]

    -q:
    +format:	Display date/time using specified format string

    If a new date/time is supplied (last parameter), the system date and
    time is updated.

    The format string is constructed as for the library function strftime
    (cf printf).  The following format specifiers are supported:

	a	Short day name
	A	Full day name
	b	Short month name
	B	Full month name
	c	Date and Time (%x %X)
	d	Day of month, 2 digits
	D	Long date (%d/%m/%y)
	E	Era name and year
	F	Full month name
	h	Short month name
	H	24 Hour, 2 digits
	I	12 Hour, 2 digits
	j	Day of year, 3 digits
	m	Month number, 2 digits
	M	Minute number, 2 digits
	n	Newline character
	o	Era year (from 0)
	N	Era name (AD)
	p	AM/PM
	r	12 hour Time (%I:%M:%S %p)
	S	Second number, 2 digits
	t	Tab character
	T	24 Hour Time (%H:%M:%S)
	U	Sunday Week of year, 2 digits
	w	Weekday number, 2 digits
	W	Monday Week of year, 2 digits
	x	Short date (%d/%m)
	X	Short Time (%I:%M)
	y	Year number, 2 digits
	Y	Year number, 4 digits
	Z	Time zone
	z	Time zone

	Field justification and precision can be specified in a similar
	manner to that in printf using digits, . and -.  Any specified
	field width/precision overrides the default.

	%	Format symbol
	.	Precision
	-	Left Justified
	number	Before a precision, the field width.  After a precision,
		the field precision.  Thus %6.5I for 1400 hours gives
		' 00014'.


dd - Data copy

    usage: dd [ ibs=numeric ] [ obs=numeric ] [ cbs=numeric ] [ bs=numeric ]
	      [ if=filename ] [ of=filename ] [ skip=numeric ] [ seek=numeric ]
	      [ count=numeric ] [ files=numeric ]
	      [ conv=[lcase,ucase,noerror,sync,swab,ascii,ebcdic,ibm] ]

    ibs		Input block size
    obs		Output Block size
    cbs		Conversion block size
    bs		Block size
    if		Input filename (default: stdin)
    of		Output filename (default: stdout)
    skip	Number of input records to skip
    seek	Number of output records to seek over
    count	Number of records to transfer
    files	Number of files to process
    conv	Convert data to
		lcase   - lower case
		ucase   - upper cas
		noerror - ignore errors
		sync	-
		swab	- Swap bytes
		ascii	- ASCII
		ebcdic	- EBCDIC
		ibm	- IBM EBCDIC


df - Display Disk Free space

    usage: df [ -bit] drives

    -b: Display in BSD format (kbytes)
    -i: Display cluster information
    -t: Display totals
    -c: Display drive information


diff - Display differences between two text files.

    usage: diff [ -bceinT ] [ -o output file ] file1 file2

    -b		Remove trailing whitespace (blanks and tabs) and compress all
    		other strings of whitespace to a single blank.
    -c		Print some context -- matching lines before and after the
    		non-match section.  Mark non-matched sections with "|".
    -e		Output is in an "editor script" format which is compatible
    		with the Unix 'ed' editor.
    -i		Ignore lower/upper case distinctions.
    -n		Output is in an RCS style format for use with RCS tools.
    -o outfile	Place output in file "outfile" rather than on stdout.
    -T		Print timings


dirname - Extract directory name from filename

    usage: dirname filename


du - Display disk usage

    usage: du [-arsk] [startdir]

    -a: Display all entries instead of just directory entries
    -r: Report errors
    -s: Only display top level values
    -k:	Display Kilobyte usage as well


expr - evaluate arguments as expression

    usage: expr expression..

    The supported operators are |, &, =, >, >=, <, <=, !=, +, -, *, /, %
    and : and ().


fgrep - Search file for string

    usage: fgrep [-vxcilnbs] [-e string] [-f file] [string] [files..]

    -x:		Report only lines which exactly match the string.
    -v:		All lines but those matching are printed.
    -c:		Only a count of	matching lines is printed.
    -i:		Ignore upper/lower case	distinction during comparisons.
    -l:		Only the names of files	with matching lines are	listed (once),
		separated by new-lines.
    -n:		Each line is preceded by its relative line number in the file.
    -b:		Each line is preceded by the block number on which it was found.
		This is sometimes useful in locating disk block numbers by
		context.
    -s:		The error messages produced for	nonexistent or unreadable files
		are suppressed.
    -e expression
		Same as a simple expression argument, but useful when the
		expression begins with a -.
    -f file	The regular expression list is taken from the file.


find - Search directory tree for files matching requirements

    usage: find path-list predicate-list
	   Predicate list: [ -name filename ] [ -perm permissions ]
			   [ -type [bcdfpnlsM] ] [ -links number ]
			   [ -user username ] [ -group groupname ]
			   [ -size number[bkc] [ -inum inode ]
			   [ -[acm]time days.HHMMSS ]
			   [ -[exec | ok ] command string ; ]
			   [ -newer[acm][acm] file ] [ -path path ]
			   [ -depth ] [ -print ] [ -mountstop ]
			   [ -prune ] [ -only ] [ -follow ]
			   [ -msdos ] [ -pmask permissions mask ]
			   [ -cpio|ncpio device ] [ -ls ] [ -icase ]
			   [ -nogroup ] [ -nouser ] [ -xdev ]
			   [ -chop depth ]
	   Operator  list: [ -a -o ( ) ! ]

	Predicates

	    -name filename:		Match this file name.  Shell wild
					cards can be used.
	    -perm permissions		Match Permissions
	    -type [bcdfpnlsM] 		Match only files of specified type
	    -links number		Match number of links
	    -user username 		Match owner
	    -group groupname		Match group
	    -size number[bkc]		Match file size
	    -inum inode			Match inode number
	    -[acm]time days.HHMMSS	Match create/access modification time
	    -[exec | ok] command string ;
					Execute command string
	    -newer[acm][acm] file 	Compare create/access/modification
					time with reference file
	    -path path			Match full path using wild cards
	    -depth 			Depth first search
	    -print 			Print a match
	    -mountstop			Do not cross mount points
	    -prune 			Prune directories (same as -chop 1)
	    -chop depth			Chop directory tree at depth
	    -only 			Only follow directories
	    -follow			Follow symbolic links
	    -msdos 			Output WIN format names
	    -pmask permissions mask	Test file permissions to see if a
					any of permissions mask is set.
	    -cpio | ncpio device 	Write file to stdout in CPIO format
	    -ls 			Print file information in ls format
	    -icase			Ignore case on name match
	    -nogroup 			Match if file's group name does not
	    				exist
	    -nouser			Match if file's owner name does not
					exist
	    -xdev			Do not go cross mount points

	Predicates can be joined using the following operators

	   -a	And
	   -o	Or
	   !	Not
	   (	Start subexpression
	   )	End subexpression


fold - Fold long lines to stdout

    usage: fold -width files..

    -width	Maximum line length (default 80)


grep - Search file for pattern

    usage: grep [-vcilnbs] [-e string] [-f file] [string] [files..]

    -v:		All lines but those matching are printed.
    -c:		Only a count of	matching lines is printed.
    -i:		Ignore upper/lower case	distinction during comparisons.
    -l:		Only the names of files	with matching lines are	listed (once),
		separated by new-lines.
    -n:		Each line is preceded by its relative line number in the file.
    -b:		Each line is preceded by the block number on which it was found.
		This is sometimes useful in locating disk block numbers by
		context.
    -s:		The error messages produced for	nonexistent or unreadable files
		are suppressed.
    -e expression
		Same as a simple expression argument, but useful when the
		expression begins with a -.
    -f file	The regular expression list is taken from the file.


head - display file headers

    usage: head [-n] [file ...]

    -n:		Number of lines to display (n is a number)


ls - List directory

    Note:  Not all the options are meaning full.

    usage: ls [-xutsrpqonmligfdcbaACFRS1] [file list]

    -A:		List all files
    -F:		Append file type to filename (/ directory, * executable)
    -C:		Use column output
    -R:		Recurse down directory tree
    -S:		Sort on size
    -1:		Output as a single column
    -x:		Output as multiple columns
    -u:		Display access times, not modification times
    -t:		Sort on time
    -s:		Display number of blocks
    -r:		Reverse sort order
    -p:		Append / to directories
    -q:		Display non-printing characters as ?
    -o:		Display file owner
    -n:		Display owner/group as numeric ids
    -m:		Display in columns using , as the separator
    -l:		Long format
    -i:		Display inode
    -g:		Display file group
    -f:		Assume the file is a directory
    -d:		Do not recurse down a directory
    -c:		Display creation times, not modification times
    -b:		Display non-printing characters as \value
    -a:		Suppress files beginning with a dot


m4 - M4 Macro processor

    usage: m4 [-es] [-Tsize] [-Bsize] [-Ssize] [-Hsize] [-Dname[=val]] [-Uname] [files..]

    -e:		Operate interactively
    -s:		Enable line sync output
    -T size:	Set token buffer size to size.
    -B size:	Set argument buffer size to size.
    -S size:	Set call stack size to size.
    -H size:	Set hash table size to size.
    -D name=..	Define name value
    -U name	Undefine name


make - Makefile processor (supports swapping a la shell)

    usage: make [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]

    -f name:	Makefile name (default makefile)
    -i:		Ignore exit status
    -n:		Pretend to make
    -p:		Print all macros & targets
    -q:		Question up-to-dateness of target.  Return exit status 1 if not
    -r:		Don't not use inbuilt rules
    -s:		Make silently
    -t:		Touch files instead of making them
    -d:		Debug
    -e:		Override with environment variables
    -k:		Skip tree

    Note:  Make sure the rulefile is installed in the same directory as
	   make.exe.


mkdir - Make path

    usage: mkdir -p directory

    -p:	Make intermediate directories in path


mv - Move files.

    usage: mv [-ipfrRvn] f1 f2
	   mv [-ipfrRvn] f1 ... fn d1
	   mv [-ipfrRvn] d1 d2

    -i:	Ask before copying
    -r: Recurse down directories, copying tree to new location
    -R: Recurse down directories, copying tree to new location
    -v: Verbose
    -n: Show me what you're going to do, without doing it.
    -p: Preserve access times
    -f: Force removal of destination files


od - octal dump

    usage: od [-bcdhox] [file] [ [+] offset [.] [b] ]

    -b:		Display bytes in octal
    -c:		Display bytes as characters
    -d:		Display bytes in decimal
    -h:		Display bytes in hexadecimal
    -o:		Display words in octal
    -x:		Display words in hexadecimal

    offset	Start offset (in octal) in file
		(b - offset is in blocks)
		(. interprete offset in decimal)


printenv - Print environment to stdout

    usage: printenv


rm - Remove files

    usage: rm [ -fir ] file...

    -f:	Force removal
    -i: Ask user first
    -r: Recurse down directories (beware the dread rm -rf /*).


rmdir - Remove directories

    usage: rmdir [ -p ] path..

    -p:	Remove all directories on path


sleep - Wait for n seconds

    usage: sleep seconds


sort - Sort files

    usage: sort [ -cmu ] [ -t separator] [ -y record size] [ -z memory size ]
		[-o output file] [ -T directory ] [ -bdfinrM ]
		[[+StartField.Offset[bdfinrM] [-EndField.Offset]] [file] ...

    If any of the following flags can be applied globally or to a particular
    field (appended to the startfield address):

    -b:	Skip leading blanks
    -d:	Sort to dictionary order.  Only letters, digits, comma's and points
	are compared.
    -f:	Fold upper case to lower.
    -i:	Ignore chars outside ASCII range (040 - 0176)
    -n:	Sort to numeric value (optional decimal point) implies -b
    -r:	Reverse the sense of comparisons.
    -M:	Month order

    I/O control flags are:

    -u:		Print uniq lines only once.
    -c:		Check if files are sorted in order.
    -m:		Merge already sorted files.
    -o outfile:	Name of output file. (Can be one of the input files). Default
		is stdout.
    -:		Take stdin as input.

    Fields:

    -t'x':	Field separating character is 'x'
    +a.b:	Start comparing at field 'a' with offset 'b'. A missing 'b' is
		taken to be 0.
    -a.b:	Stop comparing at field 'a' with offset 'b'. A missing 'b' is
		taken to be 0.  A missing -a.b means the rest of the line.


split - Split file into n line parts

    usage: split [-n] [file [name]].

    -number:	Part size in lines (default: 1000)
    file:	The file to split
    name:	The prefix for the parts (default: x).


strings - Display the strings in files

    usage: strings -aopc -min_length files...

    -a:			No used
    -o:			Output offset of string
    -p:			Output filename for string
    -c:			No used
    -min_length		The minimum string length


tail - Print tail of file

    usage: tail [+/-[number][lcbf]] [file]

    +/-number	Number of lines (l, default), characters (c), blocks (b) to
		print from the end (-) or start (+) of the file.
    -f		Wait 1 second at EOF and try reading again.


tee - Pipe fit a pipeline.  Copy stdin to one or more files and standard
      output.

    usage: tee [-i] [-a] [files].

    -i:	Interrupt turned off.
    -a:	Append to outputfile(s), instead of overwriting them.


touch - Change a file's timestamp or size

    usage: touch [-amc] [-s newsize] [-t mmddhhmm[CC]yy.ss] [-f ref_file] file...
    -a:			Change the access time
    -m:			Change the modification time
    -c:			Change the create time
    -s newsize:		Change the file size to newsize
    -t time:		Use this as the timestamp
    -f ref_file:	Use the reference file (ref_file) for the timestamps.

tr - Translate characters

    usage: tr [-cds] string1 string2 

    -c:	Take complement of string1
    -d:	Delete input characters coded string1
    -s: Squeeze multiple output characters of string2 into one character


uniq - Display unique lines

    usage: uniq [-udc] [+n] [-n] [input [output]]


wc - Count number of words in file

    usage: wc [-lwc] [name ...]

    -l:	Display only the line count
    -w:	Display only the word count
    -c:	Display only the character count


which - Display the directory containing a command from the PATH

    usage: which [-i] [-a] [--] [<command>]

    -i:	Read commands from stdin
    -a: Display all commands found on the PATH