If I run the following command I get the expected output as shown.
jonathan@Aristotle:~/EclipseWorkspaces/AGI/ShellUtilities$ df --output=fstype,source $(pwd)
Type Filesystem
ext4 /dev/sdb1
If I place the same command in a function and invoke the function from the command line I see no output. Where has stdout gone and why?
#
# Copyright © Jonathan Gossage, 2016
#
# getFileSystemInfo
#
function getFileSystemInfo {
# Get an item of information related to the file system that contains a
# specific file or directory.
# $1 is the file or directory to be checked
# $2 is the specific information type to be checked. See df(1) FIELD_LIST
# for full details. As in df you can get more than one type of
# information.
# To access the information returned, capture stdout in your script.
echo "We are in getFileSystemInfo"
df --output=$2 "$1"
return $?
}
jonathan@Aristotle:~/EclipseWorkspaces/AGI/ShellUtilities$ Sourced/getFileSystemInfo $(pwd) fstype,source
getFileSystemInfo
in subdirectorySourced
- that's not the same as sourcing a function definition within the current shell.getFileSystemInfo "$@"
. Otherwise, you're just invoking a script that (by itself) takes no parameters and does nothing.