可以親眼見到1比1真人尺寸萊莎與伊織萌!等身大萊莎Figure揭幕會來了!   「Pokémon HOME」正式開放!帶著歷代的寶可夢們一起展開旅程吧!   今秋釋出一系列新推PS4硬體套裝為《FIFA 21》上場暖身   這次贈送的主題背景是紙片瑪利歐!「第10屆 TETRIS®王者盃 紙片瑪利歐 摺紙國王合作祭」即將開跑!   PS5新語音聊天功能詳細解說   先睹為快:PlayStation 5次世代使用者體驗   益智遊戲「Pokémon Café Mix」即將在Nintendo Switch、手機上登場!開放事前登錄中   『仁王2』第三波付費DLC「太初武士秘史」今日開放下載!解開所有謎團,為漫長的旅途畫下句點 

Bash 執行「字串命令」的方法

Linux 的 Bash shell 裡面,若有一個字串需要執行,可以怎麼做呢?

Bash 執行「字串命令」的方法

Bash shell 要將此字串當 Shell 命令執行,可以有下述兩種作法:

  1. eval
  2. bash -c
    • If the -c option is present, then commands are read from the first non-option argument command_string.
    • If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters.
    • The assignment to $0 sets the name of the shell, which is used in warning and error messages.

分別測試作法:(執行結果都一樣)

  1. eval “cd /; ls” # 執行完,帳號會在 / 的路徑上
  2. bash -c “cd /; ls” # 執行完,帳號還是在原始位置
  3. source

相關文章