Skip to content

Instantly share code, notes, and snippets.

@garywill
Created February 8, 2025 13:26
Show Gist options
  • Select an option

  • Save garywill/c4633f0e82497e6a62b00137908861fa to your computer and use it in GitHub Desktop.

Select an option

Save garywill/c4633f0e82497e6a62b00137908861fa to your computer and use it in GitHub Desktop.
Terminal many tabs with different commands running in (xfce4 terminal)
#!/bin/bash
arr_tab_run_cmd=("$@")
nargs=${#arr_tab_run_cmd[@]}
terminal_args=(--window)
for ((i=0; i<nargs; i++)); do
if [ $i -eq 0 ]; then
echo "第一个tab: ${arr_tab_run_cmd[$i]}"
terminal_args+=(-H -e)
else
echo "更多tab: ${arr_tab_run_cmd[$i]}"
terminal_args+=(--tab -H -e)
fi
# 使用 printf "%q" 安全转义命令参数
escaped_cmd=$(printf "%q" "${arr_tab_run_cmd[$i]}")
terminal_args+=("bash -c $escaped_cmd")
done
# echo "传给终端程序的所有参数:"
# printf "%s\n" "${terminal_args[@]}"
xfce4-terminal "${terminal_args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment