簡體   English   中英

設置bashrc時出現“沒有此類文件或目錄”的sed錯誤

[英]sed error of “no such file or directory” in setting up bashrc

很抱歉提出一個對於一些有經驗的人來說似乎很幼稚的問題。 當嘗試如下修改〜/ .bashrc時,我不擅長Linux:

sed -i s/'history -cw'//g .bash_logout

當我獲取它時,我收到一條錯誤消息:

sed:無法讀取.bash_logout:沒有此類文件或目錄

這是什么意思,我該如何解決?

非常感謝你。

問題是您沒有使用路徑。 如果您只是想刪除該行,請使用:

sed -i s/'history -cw'//g .bash_logout  #if I am in the current dir

要么

sed -i s/'history -cw'//g ${HOME}/.bash_logout

要么

sed -i s/'history -cw'//g ~/.bash_logout

要么

sed -i s/'history -cw'//g /path/to/.bash_logout

要添加到文件,請考慮以下事項:

#!/bin/bash
if ! grep -q "history -cw" .bash_logout ;then
        echo "lets add this baby"
        echo "history -cw" >> .bash_logout
else
        echo "it is already there, don't add .."
fi

注意:您當前的問題是您沒有指定文件所在的路徑。 盡可能明確:

該腳本將值設置為完整路徑,並在嘗試執行任何操作之前檢查該文件是否首先存在:

LOGOUT="/home/user/.bash_logout"
if [ ! -f "$LOGOUT" ] ;then
        echo "file not found"
        exit
fi

if ! grep -q "history -cw" "$LOGOUT" ;then
        echo "lets add this baby"
        echo "history -cw" >> "$LOGOUT"
else
        echo "it is already there, don't add .."
fi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM