AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 777040
Accepted
Jonathan
Jonathan
Asked: 2016-05-25 14:22:09 +0800 CST2016-05-25 14:22:09 +0800 CST 2016-05-25 14:22:09 +0800 CST

函数内部的 stdout 发生了什么?

  • 772
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

如果我将相同的命令放在一个函数中并从命令行调用该函数,我看不到任何输出。标准输出去了哪里,为什么?

#
# 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
command-line
  • 1 1 个回答
  • 42 Views

1 个回答

  • Voted
  1. Best Answer
    steeldriver
    2016-05-26T06:13:28+08:002016-05-26T06:13:28+08:00

    您的示例中没有stdout:将 shell 函数定义包装在脚本文件中,然后调用脚本不会执行该函数。您需要获取脚本,以便该函数在当前 shell 中可用

    . Sourced/getFileSystemInfo
    getFileSystemInfo $(pwd) fstype,source
    

    或修改脚本,使其调用函数并将自己的参数传递给它,方法是添加一行,例如

     getFileSystemInfo "$@"
    

    现在,您只是调用一个什么都不做的脚本,而位置参数被忽略。

    • 1

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve