How to add code to .bashrc without causing errors?
I'm learning how to passthrough my NIC to my KVM.
This guide https:/
#!/bin/bash
# change the 999 if needed
shopt -s nullglob
for d in /sys/kernel/
n=$
printf 'IOMMU Group %s ' "$n"
lspci -nns "${d##*/}"
done;
I'm unclear where the code should be inserted, so it's in lines 1-8.
1 #!/bin/bash
2 # change the 999 if needed
3 shopt -s nullglob
4 for d in /sys/kernel/
5 n=${d#*
6 printf 'IOMMU Group %s ' "$n"
7 lspci -nns "${d##*/}"
8 done;
9
10 # ~/.bashrc: executed by bash(1) for non-login shells.
11 # see /usr/share/
12 # for examples
13
14 # If not running interactively, don't do anything
15 case $- in
16 *i*) ;;
17 *) return;;
18 esac
19
20 # don't put duplicate lines or lines starting with space in the history.
21 # See bash(1) for more options
22 HISTCONTROL=
23
24 # append to the history file, don't overwrite it
25 shopt -s histappend
26
27 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
28 HISTSIZE=1000
29 HISTFILESIZE=2000
30
31 # check the window size after each command and, if necessary,
32 # update the values of LINES and COLUMNS.
33 shopt -s checkwinsize
34
35 # If set, the pattern "**" used in a pathname expansion context will
36 # match all files and zero or more directories and subdirectories.
37 #shopt -s globstar
38
39 # make less more friendly for non-text input files, see lesspipe(1)
40 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
41
42 # set variable identifying the chroot you work in (used in the prompt below)
43 if [ -z "${debian_
44 debian_chroot=$(cat /etc/debian_chroot)
45 fi
46
47 # set a fancy prompt (non-color, unless we know we "want" color)
48 case "$TERM" in
49 xterm-color|
50 esac
51
52 # uncomment for a colored prompt, if the terminal has the capability; turned
53 # off by default to not distract the user: the focus in a terminal window
54 # should be on the output of commands, not on the prompt
55 #force_
56
57 if [ -n "$force_
58 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
59 # We have color support; assume it's compliant with Ecma-48
60 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
61 # a case would tend to support setf rather than setaf.)
62 color_prompt=yes
63 else
64 color_prompt=
65 fi
66 fi
67
68 if [ "$color_prompt" = yes ]; then
69 PS1='${
70 else
71 PS1='${
72 fi
73 unset color_prompt force_color_prompt
74
75 # If this is an xterm set the title to user@host:dir
76 case "$TERM" in
77 xterm*|rxvt*)
78 PS1="\[
79 ;;
80 *)
81 ;;
82 esac
83
84 # enable color support of ls and also add handy aliases
85 if [ -x /usr/bin/dircolors ]; then
86 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
87 alias ls='ls --color=auto'
88 #alias dir='dir --color=auto'
89 #alias vdir='vdir --color=auto'
90
91 alias grep='grep --color=auto'
92 alias fgrep='fgrep --color=auto'
93 alias egrep='egrep --color=auto'
94 fi
95
96 # colored GCC warnings and errors
97 #export GCC_COLORS=
98
99 # some more ls aliases
100 alias ll='ls -alF'
101 alias la='ls -A'
102 alias l='ls -CF'
103
104 # Add an "alert" alias for long running commands. Use like so:
105 # sleep 10; alert
106 alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1 |sed -e '\''s/^
107
108 # Alias definitions.
109 # You may want to put all your additions into a separate file like
110 # ~/.bash_aliases, instead of adding them here directly.
111 # See /usr/share/
112
113 if [ -f ~/.bash_aliases ]; then
114 . ~/.bash_aliases
115 fi
116
117 # enable programmable completion features (you don't need to enable
118 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
119 # sources /etc/bash.bashrc).
120 if ! shopt -oq posix; then
121 if [ -f /usr/share/
122 . /usr/share/
123 elif [ -f /etc/bash_
124 . /etc/bash_
125 fi
126 fi
However this causes an error when running .bashrc with the command ./.bashrc
ubuntu@ubuntu:~$ ./.bashrc
./.bashrc: line 17: return: can only `return' from a function or sourced script
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Manfred Hampl
- Solved:
- Last query:
- Last reply: