【问题标题】:how to create a file with the cmd?如何使用 cmd 创建文件?
【发布时间】:2014-07-27 19:15:55
【问题描述】:

我有一台 win7 机器,我使用 Git Shell(似乎是 Windows Powershell)

我正在尝试遵循 GIT IMMERSION (http://gitimmersion.com/lab_03.html) 的 Lab 3 教程。

我不知道怎么create a file named hello.rb with the contents below.

puts "Hello, World"

感谢任何帮助。非常感谢!

【问题讨论】:

  • 除非我遗漏了什么,你不能把那行粘贴到记事本中,然后把文件保存在适当的地方吗?

标签: git powershell github cmd


【解决方案1】:

如果是Powershell,则使用Set-Content

Set-Content hello.rb 'puts "Hello, World"'

【讨论】:

  • 正确答案如何?它在 git shell 中不起作用。
  • @Swonkie GitHub 为 Windows 提供的“Git Shell”是 configurable 以使用您选择的 shell。 OP表示它可能是Powershell,所以这就是我用来回答的。
  • 啊,我明白了。不知道来自 GitHub 的版本。我仍然更喜欢我的解决方案,因为它几乎可以在任何 shell(甚至 PowerShell)中工作。
  • @Swonkie Git Shell 可配置为使用 Git Bash,但默认 shell 是 Powershell。
【解决方案2】:

Git Shell 是 bash,而不是 PowerShell。

echo 'puts "Hello, World"' > hello.rb

【讨论】:

  • 你需要去掉单引号。这不是他想要的:)
  • 是的,它们是必需的 - 它们不会出现在文件中。
  • 不清楚是bash。例如,如果您为 Windows 安装 GitHub,它会创建一个“Git Shell”链接,该链接是 powershell,并在您的路径中添加了 git 命令。
  • 当我在 Windows 7 机器上打开 git shell 时,窗口标题中显示“Git Bash”。 $BASH_VERSION 的值为 3.1.0(1)-release
猜你喜欢
  • 2017-09-12
  • 2014-04-21
  • 2015-06-10
  • 2014-04-11
  • 1970-01-01
  • 1970-01-01
  • 2017-05-16
  • 2020-06-25
  • 2013-09-19
相关资源
最近更新 更多