by Jacob Evelyn

雅各布·伊夫林(Jacob Evelyn)

那个时候我不小心改写了Bash ... (That time I accidentally overwrote Bash… in Bash)

“我知道我在做什么。” (“I know what I’m doing.”)

Five years ago, a few weeks into my very first Programming Job™, I was tinkering around in bash trying to get some code to run.

五年前,也就是我第一次编程工作™的几周后,我在进行bash修改,试图运行一些代码。

I was becoming increasingly frustrated. Why wasn’t that file in my $PATH? It should have been, I felt certain of that.

我变得越来越沮丧。 为什么我的$PATH没有该文件? 我本该确定应该的。

But, growing more and more desperate to get something to work, I moved the file to a folder I knew was in the $PATH:

但是,越来越大,越来越迫切希望得到的东西的工作,我搬到文件到我所知道的是在一个文件夹$PATH

> mv ./file.whatever /bin

At least, that’s what I meant to type. In reality what I typed was:

至少,这就是我键入。 实际上,我键入的是:

> mv ./file.whatever /bin/bash

My employer-provided MacBook Pro yelled at me, like any good UNIX system:

我的雇主提供的MacBook Pro对我大叫,就像任何好的UNIX系统一样:

mv: rename ./file.whatever to /bin/bash: Operation not permitted

And like any good programmer, I blindly added a sudo and typed in my password as quickly as I could. Stupid computer, thinking it knows better than me.

像任何优秀的程序员一样,我盲目添加了sudo并尽快输入密码。 愚蠢的计算机,以为它比我更了解。

Having just unknowingly overwritten the very shell I was using, I was shocked to find my code still wouldn’t run.

在不知不觉中覆盖了我正在使用的外壳的情况下,我震惊地发现我的代码仍然无法运行。

“我不知道我在做什么,但是没关系。” (“I don’t know what I’m doing but it’s okay.”)

I opened a new OS X Terminal tab to try a new approach to getting my code running, and instead saw this:

我打开了一个新的OS X终端选项卡,尝试一种新方法来运行我的代码,但看到了以下内容:

> permission denied: ./file.whatever
[Process completed]

Hmm, that’s weird. Not sure why bash isn’t working, but at least it’s doing something with my file!

嗯,这很奇怪。 不知道为什么bash不起作用,但至少它对我的文件有作用!

I switched back to my previously-open bash shell and continued trying a few commands. They still worked, of course, because the bash program was already in memory at the time I overwrote its executable.

我切换回以前打开的bash shell,并继续尝试一些命令。 当然,它们仍然有效,因为在我重写可执行文件时, bash程序已经在内存中。

So some Terminal tabs aren’t working, but others are. Probably ghosts in the machines.

因此,某些终端选项卡不起作用,而其他选项卡则起作用。 机器中可能有鬼影。

To sort out this weird-but-definitely-probably-not-a-big-deal bash behavior I decided to do the tried-and-true cure-all: quit the app (Terminal) and open it again.

为了解决这种怪异但肯定不是大交易的bash行为,我决定进行尝试并真正解决所有问题:退出应用程序(终端),然后再次打开它。

“天啊! 我做了什么?” (“Oh god! what have I done?”)

Out of nowhere, the reality of what had happened hit me like a snowball to the face. Oh no oh no oh no I just overwrote Bash.

无处不在,发生的事情的现实像雪球一样击中了我。 哦,不,不,我只是重写了Bash。

I no longer cared about getting my code to run. All I wanted to do was go back to the way things were.

我不再关心让我的代码运行。 我要做的就是回到原来的样子。

“这可能是可以解决的……” (“This is probably fixable…”)

I spent a long time Googling things like “deleted bash” and “download new bash OS X” and got nowhere. I was in too much of a panic to think about using other shells — which I vaguely knew about, but didn’t realize were already installed on my machine. (And I certainly didn’t realize these shells were also usable by just changing a setting in the Terminal app. #facepalm)

我花了很长时间谷歌搜索诸如“删除bash”和“下载新bash OS X”之类的东西,却一无所获。 我实在太着急了,无法考虑使用其他外壳了-我隐约知道,但没有意识到已经安装在我的机器上了。 (而且我当然不知道仅通过在终端应用程序中更改设置即可使用这些shell。#facepalm)

Eventually, I sheepishly confessed to some coworkers what I had done and after we all had a good chuckle I got one of them to email me a copy of his bash program so I could manually move it back into the /bin folder in Finder. (Hooray for point-and-click interfaces!)

最终,我令人毛骨悚然地向一些同事坦白了我的所作所为,当所有人都欢呼雀跃之后,我让其中一个人通过电子邮件将他的bash程序的副本发送给我,以便我可以将其手动移回Finder中的/bin文件夹。 (万岁的点击界面!)

Except… Finder wouldn’t let me go to the /bin folder. OS X (that version of it, at least) hid /bin and other system folders it deemed unsafe for meddling users like me to see. Stupid computer, thinking it knows better than me.

除了…Finder不允许我进入/bin文件夹。 OS X(至少是该版本)隐藏了/bin和其他系统文件夹,对于像我这样的用户来说,这样做是不安全的。 愚蠢的计算机,以为它比我更了解。

So I Googled some more, this time for things like “view hidden folders in Finder.” I found a handful of different ways to do that, but every single one of them required me to type some magic command… into bash, which I could no longer open. Kids: if you delete your shell but have an instance of it open, don’t close it!

因此,我这次在Google中搜索了更多内容,例如“在Finder中查看隐藏的文件夹”。 我找到了几种不同的方法来执行此操作,但是每个方法都要求我在bash键入一些魔术命令…,我无法再打开它。 孩子们:如果删除外壳程序但打开了它的实例,请不要关闭它!

“好吧...这也许可以解决...” (“OK… this is maybe fixable…”)

At a loss for what to do next, I found an old internal Q&A system the company had and posted a quick description of my problem, trying to strike that balance in tone between heh what a funny but probably not uncommon situation, right everyone? and please someone anyone help me I’m panicking. The site looked like it wasn’t ever used anymore but I was hoping someone got an email when a question was posted.

不知所措,下一步我发现公司有一个旧的内部问答系统,并快速描述了我的问题,试图在两种有趣但可能不常见的情况之间取得平衡,对吗? 请有人帮助我感到恐慌 。 该网站看起来好像已经不再使用了,但是我希望有人在发布问题时能收到电子邮件。

Lo and behold, my Hail Mary quickly got a response: someone recommended booting from a Linux Live CD (this was back when computers had CD drives), and then from within Linux accessing my OS X file system to add bash back to its rightful place. I understood about a third of the suggestion, but went ahead anyway — what other options did I have? I found a Linux CD, did a bunch of things I didn’t understand to get it to work, and waited impatiently as the machine went through all of the myriad setup steps until — voilà! A desktop appeared!

瞧,我的冰雹玛丽很快得到了回应:有人建议从Linux Live CD引导(这在计算机具有CD驱动器时返回),然后从Linux内部访问我的OS X文件系统以将bash添加回其应有的位置。 。 我理解了大约三分之一的建议,但无论如何都继续进行-我还有什么其他选择? 我找到了一张Linux CD,做了很多我不了解的事情才能使它正常工作,并且不耐烦地等待着机器经过所有无数的设置步骤,直到– 瞧! 桌面出现了!

I Googled around until I found out how to mount the OS X filesystem, and eagerly opened bash (what a good feeling!) to copy that machine’s bash executable back over to OS X… only to encounter an error message: the OS X partition was read-only from Linux. I did find out about a way to make it writable, but that required restarting back in OS X and — you guessed it — running a command in bash.

我四处搜寻,直到我发现如何挂载OS X文件系统,然后急切地打开bash (感觉真好!)将那台机器的bash可执行文件复制回OS X……只是遇到一条错误消息:OS X分区是从Linux只读。 我确实找到了使它可写的方法,但是需要在OS X中重新启动,并且-您猜对了-在bash运行命令。

I tried a few different Linux Live CDs (each of which took about forty minutes of impatient pacing to boot), but each had the same result. Once again: if you delete your shell but have an instance of it open, don’t close it!

我尝试了几种不同的Linux Live CD(每张CD大约需要四十分钟不耐烦的节奏启动),但是每张光盘都具有相同的结果。 再说一次:如果删除外壳程序但打开了它的实例, 请不要关闭它!

“无论如何,可修复甚至意味着什么?” (“What does fixable even mean anyway?”)

Unsure where to go from there, I reached out to coworkers again and eureka! — someone knew of a way to navigate to any folder — even hidden ones — within Finder. All I had to do was restart in OS X again, copy the emailed bash executable to /bin, and everything would be gravy. So I shut down Linux, removed the Live CD, restarted in OS X, and…

不确定从那里去哪里,我再次联系了同事, 尤里卡! —有人知道在Finder中导航到任何文件夹(甚至是隐藏文件夹)的方法。 我要做的就是再次在OS X中重新启动,将通过电子邮件发送的bash可执行文件复制到/bin ,一切都会变得很糟。 所以我关闭Linux,取出Live CD,在OS X中重新启动,然后…

Hmm. I couldn’t log in, because, well, the OS X login process uses a shell under the hood, and guess which shell that is?

嗯 我无法登录,因为OS X的登录过程在幕后使用了一个外壳,然后猜测是哪个外壳?

Was I doomed to spend the rest of my career living off of Linux Live CDs? I pictured myself years in the future, a babbling hermit kept around to scare the new kids: “Don’t delete bash or you’ll end up like crazy old Jake.”

我是否注定要用Linux Live CD来度过余生? 我对自己的未来进行了想象,一个a咕的隐士一直在吓着新来的孩子: “不要删除bash,否则您最终会像疯了的老杰克一样。”

“我从来没有更高兴看到错误消息” (“I’ve never been happier to see an error message”)

I had given up all hope, when another coworker (goodness, these people knew so much!) told me about single-user mode, a special OS X startup mode that helps you resolve login (and other) errors. Single-user mode let me boot a bare-bones, command-line version of OS X through a different shell (/bin/sh, I think). From there, it was just a matter of finding the right incantations to get the bash executable back into /bin and off of a USB drive (where I put it in another painfully slow iteration of the Linux Live CD boot).

当另一个同事(天哪,这些人知道很多!)告诉我有关单用户模式时 ,我已经放弃了所有希望,这是一种特殊的OS X启动模式,可以帮助您解决登录(和其他)错误。 单用户模式让我通过不同的外壳(我认为是/bin/sh )引导OS X的准系统命令行版本。 从那里开始,找到合适的方法将bash可执行文件放回/bin并从USB驱动器中移出(这是我将其放入Linux Live CD引导的另一个痛苦的缓慢迭代中)的问题。

Once that was done, I restarted the Mac and all was finally well again! Well, except that of course my code still didn’t run.

完成之后,我重新启动了Mac,一切终于恢复了! 好吧,除了我的代码当然还没有运行。

翻译自: https://www.freecodecamp.org/news/i-accidentally-overwrote-bash-in-bash-e612da33da4b/

那个时候我不小心改写了Bash ...相关推荐

  1. 那个时候我不小心建立了一个间谍应用

    In the fall of 2007, my parents gave me an unforgettable gift for my sixteenth birthday: a first-gen ...

  2. 挨踢人生路--记我的10年18家工作经历 续 .转

    挨踢人生路--记我的10年18家工作经历 续 .转 from http://mvlung.blog.163.com/blog/static/30961748200971745935542/ 第13家公 ...

  3. ES6语法~解构赋值、箭头函数、class类继承及属性方法、map、set、symbol、rest、new.target、 Object.entries......

    2015年6月17日 ECMAScript 6发布正式版本 前面介绍基本语法,  后面为class用法及属性方法.set.symbol.rest等语法. 一.基本语法:  1.         定义变 ...

  4. Javascript prototype理解

    http://www.cnblogs.com/twilight/archive/2010/02/06/1664756.html 1 什么是prototype  JavaScript中对象的protot ...

  5. Windows核心编程 第四章 进程(下)

    4.3 终止进程的运行 若要终止进程的运行,可以使用下面四种方法: • 主线程的进入点函数返回(最好使用这个方法) . • 进程中的一个线程调用E x i t P r o c e s s函数(应该避免 ...

  6. es6-Symbol

    概述 ES5的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin模式),新方法的名字就有可能与现有方法产生冲突.如果有一种机制,保 ...

  7. “睡服”面试官系列第十六篇之Symbol(建议收藏学习)

    目录 1. 概述 2. 作为属性名的 Symbol 3. 实例:消除魔术字符串 4. 属性名的遍历 5. Symbol.for(),Symbol.keyFor() 6. 实例:模块的 Singleto ...

  8. php解析js的 arraybuffer_JS的所谓的第七种数据类型Symbol

    首先,为什么说叫所谓呢?因为在2007年之前Js给予我们typeof解析数据类型的一共有六种(一直有争议,但是我们暂时就按typeof来算) 'function''Number''Object''bo ...

  9. 【ES6(2015)】Symbol

    文章目录 1. 声明方式 2. Symbol.for() 3. Symbol.keyFor() 4. 作为属性名 5. 属性遍历 6. 消除魔术字符串 ES6 引入了一种新的原始数据类型 Symbol ...

最新文章

  1. 中国剩余定理与扑克游戏
  2. 从本机发送信息到另一台服务器上时中文乱码
  3. 练习:WinForm (PictureBox和Timer)
  4. Sun Solaris 9 下Squid 代理服务器的配置笔记
  5. 人工智能的未来需要M1吗
  6. linux date英文时间,date(时间),timedatectl(时区),cal(日历)的用法
  7. python下载文件并改名_第46p,8行代码,用Python批量重命名文件
  8. 启明云端分享| ESP8266\ESP32-C3\ESP32-C2三款芯片从核心系统、WIFI射频和基带、外围设备等都有哪些区别
  9. 程序员养家活口接私活必备网站(顺便用技术改变世界)
  10. 昨晚通宵把服务器格式化,重新配置环境。
  11. 语音识别学习日志 2019-7-17 语音识别基础知识准备6 {维特比算法(Viterbi Algorithm)}
  12. 架构概述之架构演化、模式与核心要素
  13. 第 19 次 CCF CSP 认证 202006-4 1246(digits)
  14. let和const注意点
  15. Outlook 2003解除附件下载限制
  16. [转]AAuto编程语言官方站 网站服务条款
  17. mips64高精度时钟引起ktime_get时间不准,导致饿狗故障原因分析【转】
  18. Redis-key的设计技巧
  19. 用matlab绘制圆锥曲线,如何用几何画板绘制圆锥曲线?
  20. 人生何尝不是一盘“大富翁”呢

热门文章

  1. 想精通单片机开发,这些必备基础知识不可不掌握
  2. 第三周总结(2018-03-12~2018-03-16)
  3. 什么叫VI、及VI的设计规范
  4. WDBS世界数字经济与区块链大会杭州站圆满落幕
  5. ZZULIOJ 1788 小金刚的宝藏 (01背包)
  6. 【社会调研】访谈个案案例分享
  7. 无人机项目跟踪六十七----电子罗盘电路
  8. Problem B – Buggy ICPC——思维,找规律
  9. GDSII format
  10. UIAutomator2的使用教程