ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sysShell::shell_type Type Reference

This is the shell_type class for generating objects to determine the runtime shell type of the operating system. More...

Public Attributes

type(shellis_typeis
 The scalar object of type shellis_type whose logical components indicate the shell name. More...
 
character(1, SK) dirsep = SK_"/"
 The scalar character of default kind SK of length 1 containing the preferred single-character shell directory separator (e.g., \ (Windows) or / (POSIX or if the shell type is unknown)). More...
 
character(1, SK) pathsep = SK_":"
 The scalar character of default kind SK of length 1 containing the preferred single-character shell path separator (e.g., ; (Windows) or : (POSIX or if the shell type is unknown)). More...
 
character(:, SK), allocatable dirseps
 The allocatable scalar character of default kind SK of arbitrary length containing all supported single-character shell directory separators (e.g., \/ (Windows) or / (POSIX or if the shell type is unknown)). More...
 
character(:, SK), allocatable name
 The allocatable scalar character containing the name of or path to the current shell. More...
 

Detailed Description

This is the shell_type class for generating objects to determine the runtime shell type of the operating system.

Note that the system shells are frequently cross-platform.
For example,

  1. Bash shell is frequently also available on Windows platforms.
  2. Microsoft PowerShell Core (pwsh) is compliant with IEEE POSIX 1003.2 standard for Unix shells and can be installed on all major operating systems.

See the documentation of shellis_type for details and meaning of the is component of objects of this type.
Note that both gfortran as of version 12 and Intel ifort as of version 2022 use the Windows Command prompt as the default shell, even if the program is compiled and run from within a POSIX-compliant shell (like Git Bash).

Frequently, the runtime shell sh is merely a symlink to a more modern shell compatible with Bourne shell.
To ensure the target shell name is correctly inferred, the program will report the target of sh if it is a symlink.

Parameters
[out]failed: The output scalar logical of default kind LK that is .true. if and only if an error occurs while inferring the system shell name.
(optional. If missing and a runtime error occurs, the program will halt by calling error stop.)
[in,out]errmsg: The input/output scalar character of default kind SK of arbitrary length type parameter.
If an error occurs, errmsg will be set to a descriptive message about the nature of the runtime error.
A length of LEN_IOMSG characters is likely sufficient to capture most error messages in full.
(optional. It can be present only if failed is also present. If missing, no error message will be output.)
Returns
shell : The output scalar object of type shell_type containing the specifics of the runtime system shell.


Possible calling interfaces

use pm_kind, only: LK
character(255, SK) :: errmsg
type(shell_type) :: shell
logical(LK) :: failed
shell = shell_type()
shell = shell_type(failed)
shell = shell_type(failed, errmsg)
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
This module contains procedures and generic interfaces for inferring the runtime system shell type an...
Definition: pm_sysShell.F90:38
This is the shell_type class for generating objects to determine the runtime shell type of the operat...
Remarks
The procedures under discussion are impure.
Note
Inferring the shell type at runtime is computationally expensive. Therefore, to avoid this extra computational cost, the procedures under this generic interface construct a static object of type shell_type which is saved within the procedures for internal usage in subsequent calls to the procedures.
The presence of such a sticky internal object should be fine even in threaded (e.g., OpenMP) applications, since the state of the object is initialized once and not changed anymore throughout the entire program life.
See also
shellis_type
isShellPosix
isShellWindows
Comparison of command shells


Example usage

1program example
2
3 use pm_kind, only: LK, IK, SK
4 use pm_io, only: display_type
5 use pm_sysShell, only: shell_type
6
7 implicit none
8
9 type(shell_type) :: Shell
10 logical(LK) :: failed
11 character(255, SK) :: errmsg
12
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("shell = shell_type()")
18 shell = shell_type()
19 call dispShell()
20 call disp%skip()
21
22 call disp%skip()
23 call disp%show("shell = shell_type(failed)")
24 shell = shell_type(failed)
25 call disp%show("failed ! Check if any error has occurred.")
26 call disp%show( failed )
27 if (failed) then
28 call disp%show("SK_'error occurred.'")
29 call disp%show( SK_'error occurred.' , deliml = SK_"""" )
30 else
31 call dispShell()
32 end if
33 call disp%skip()
34
35 call disp%skip()
36 call disp%show("shell = shell_type(failed, errmsg)")
37 shell = shell_type(failed, errmsg)
38 call disp%show("failed ! Check if any error has occurred.")
39 call disp%show( failed )
40 if (failed) then
41 call disp%show("errmsg")
42 call disp%show( errmsg , deliml = SK_"""" )
43 else
44 call dispShell()
45 end if
46 call disp%skip()
47
48contains
49
50 subroutine dispShell()
51 call disp%show("shell%is%ash ")
52 call disp%show( shell%is%ash )
53 call disp%show("shell%is%bash ")
54 call disp%show( shell%is%bash )
55 call disp%show("shell%is%csh ")
56 call disp%show( shell%is%csh )
57 call disp%show("shell%is%cmd ")
58 call disp%show( shell%is%cmd )
59 call disp%show("shell%is%dash ")
60 call disp%show( shell%is%dash )
61 call disp%show("shell%is%fish ")
62 call disp%show( shell%is%fish )
63 call disp%show("shell%is%ksh ")
64 call disp%show( shell%is%ksh )
65 call disp%show("shell%is%posix ")
66 call disp%show( shell%is%posix )
67 call disp%show("shell%is%powershell ")
68 call disp%show( shell%is%powershell )
69 call disp%show("shell%is%sh ")
70 call disp%show( shell%is%sh )
71 call disp%show("shell%is%tcsh ")
72 call disp%show( shell%is%tcsh )
73 call disp%show("shell%is%windows ")
74 call disp%show( shell%is%windows )
75 call disp%show("shell%is%zsh ")
76 call disp%show( shell%is%zsh )
77 call disp%show("shell%is%yash ")
78 call disp%show( shell%is%yash )
79 call disp%show("shell%dirsep ")
80 call disp%show( shell%dirsep , deliml = SK_"""" )
81 call disp%show("shell%name ")
82 call disp%show( shell%name , deliml = SK_"""" )
83 end subroutine
84
85end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2shell = shell_type()
3shell%is%ash
4F
5shell%is%bash
6F
7shell%is%csh
8F
9shell%is%cmd
10F
11shell%is%dash
12T
13shell%is%fish
14F
15shell%is%ksh
16F
17shell%is%posix
18T
19shell%is%powershell
20F
21shell%is%sh
22F
23shell%is%tcsh
24F
25shell%is%windows
26F
27shell%is%zsh
28F
29shell%is%yash
30F
31shell%dirsep
32"/"
33shell%name
34"dash"
35
36
37shell = shell_type(failed)
38failed ! Check if any error has occurred.
39F
40shell%is%ash
41F
42shell%is%bash
43F
44shell%is%csh
45F
46shell%is%cmd
47F
48shell%is%dash
49T
50shell%is%fish
51F
52shell%is%ksh
53F
54shell%is%posix
55T
56shell%is%powershell
57F
58shell%is%sh
59F
60shell%is%tcsh
61F
62shell%is%windows
63F
64shell%is%zsh
65F
66shell%is%yash
67F
68shell%dirsep
69"/"
70shell%name
71"dash"
72
73
74shell = shell_type(failed, errmsg)
75failed ! Check if any error has occurred.
76F
77shell%is%ash
78F
79shell%is%bash
80F
81shell%is%csh
82F
83shell%is%cmd
84F
85shell%is%dash
86T
87shell%is%fish
88F
89shell%is%ksh
90F
91shell%is%posix
92T
93shell%is%powershell
94F
95shell%is%sh
96F
97shell%is%tcsh
98F
99shell%is%windows
100F
101shell%is%zsh
102F
103shell%is%yash
104F
105shell%dirsep
106"/"
107shell%name
108"dash"
109
110


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 321 of file pm_sysShell.F90.

Member Data Documentation

◆ dirsep

character(1, SK) pm_sysShell::shell_type::dirsep = SK_"/"

The scalar character of default kind SK of length 1 containing the preferred single-character shell directory separator (e.g., \ (Windows) or / (POSIX or if the shell type is unknown)).

Definition at line 323 of file pm_sysShell.F90.

◆ dirseps

character(:, SK), allocatable pm_sysShell::shell_type::dirseps

The allocatable scalar character of default kind SK of arbitrary length containing all supported single-character shell directory separators (e.g., \/ (Windows) or / (POSIX or if the shell type is unknown)).

Definition at line 325 of file pm_sysShell.F90.

◆ is

type(shellis_type) pm_sysShell::shell_type::is

The scalar object of type shellis_type whose logical components indicate the shell name.

Definition at line 322 of file pm_sysShell.F90.

◆ name

character(:, SK), allocatable pm_sysShell::shell_type::name

The allocatable scalar character containing the name of or path to the current shell.

Definition at line 326 of file pm_sysShell.F90.

◆ pathsep

character(1, SK) pm_sysShell::shell_type::pathsep = SK_":"

The scalar character of default kind SK of length 1 containing the preferred single-character shell path separator (e.g., ; (Windows) or : (POSIX or if the shell type is unknown)).

Definition at line 324 of file pm_sysShell.F90.


The documentation for this type was generated from the following file: