
コマンドを実行してから、同じコマンドを再実行して文字列を1つだけ変更する必要があります。
たとえば、次のコマンドを実行します。
$ ./myscript.sh xxx.xxx.xxx.xxx:8080/code -c code1 -t query
そこからコマンド履歴に戻ることなく(上矢印を介して)、または別の文字列code1
に置き換える必要があります。mycode
Bashでできますか?
答え1
スクリプトの名前を変更しましたが、次のオプションがあります。
$ ./myscript.sh xxx.xxx.xxx.xxx:8080/code -c code1 -t query
スクリプトを実行した後、次を使用します。
$ ^code1^code2
...結果は次のとおりです。
./myscript.sh xxx.xxx.xxx.xxx:8080/code -c code2 -t query
man bash
「イベントインジケータ」を検索します。
^文字列1^文字列2^
迅速な交換。最後のコマンドを繰り返して、string1をstring2に置き換えます。 !!:s/string1/string2/ と同じ
@slmの回答で、今学んだグローバル置換を追加するように編集されました。https://unix.stackexchange.com/a/116626/117549:
$ !!:gs/string1/string2
これは次のように言います。
!! - recall the last command
g - perform the substitution over the whole line
s/string1/string2 - replace string1 with string2
答え2
bashの組み込み機能をfc
使用して、履歴内のコマンドを見つけて選択的に編集/実行できます。help fc
追加の文書を作成するには、bashの組み込み機能を使用してください。
fc -s code1=code2
前のコマンドで発生したすべてのcode1を見つけてcode2に変更し、新しいコマンドを実行します。
複数の特殊文字を変更する必要がある場合に便利です。前のコマンドが次のようになっているとします。
$ java a/b/c/d
# Then,
fc -s /=.
# will produce
$ java a.b.c.d