I'm assuming you're using Ubuntu Desktop as you didn't specify otherwise.
You can create a wireless network configuration that will be managed by Network Manager by creating files in /etc/NetworkManager/system-connections
. Look at existing files to see how the format looks like.
Once the connection is created, you can use the nmcli
command to manage NetworkManager from the command line, doing things such as enabling, disabling and querying connections.
Incidentally, the System Testing tool (checkbox) has a script that does exactly this: creates a connection and enables it, with parameters that you supply on the command line.
For instance, this creates a connection to the open "duck" network:
sudo /usr/share/checkbox/scripts/create_connection duck
This will create a connection to a network using WPA2 security, with "wings" password:
sudo /usr/share/checkbox/scripts/create_connection -S wpa -K wings duck
The script is written in Python so it should be easy for you to look at and adapt to your needs.
The script's help says this:
Usage: create_connection [options] SSID
Options:
-h, --help show this help message and exit
-S SECURITY, --security=SECURITY
The type of security to be used by the connection.
One of wpa and wep. No security will be used if
nothing is specified.
-K KEY, --key=KEY The encryption key required by the router.
-U UUID, --uuid=UUID The uuid to assign to the connection for use by
NetworkManager. One will be generated if not
specified here.
-R RETRIES, --retries=RETRIES
The number of times to attempt bringing up the
connection until it is confirmed as active.
-I INTERVAL, --interval=INTERVAL
The time to wait between attempts to detect the
registration of the connection.
One possibility is that the backslash key has become bound to some readline command (readline
is the library that allows in-situ editing of shell commands, for example binding Ctrl+h to the backward-delete-char
action).
To test if that might be the case, you can try starting a bash subshell with readline editing disabled
bash --noediting
If the backslash key works in that subshell, then the places to look for the rogue keybinding definition would be /etc/inputrc
for the global configuration and ~/.inputrc
for per-user configuration. You could also try printing out and searching the currently defined keybindings from the command line using
bind -P | grep '\\\\'
The extra backslashes are required because a literal backslash will appear in the readline configuration as \\
, each of which needs a further escape in the shell. Obviously you can only do that in the subshell, if the backslash is being bound in the regular shell.
FYI there is a bind
command option to remove a binding, but it is not clear how to input the keyseq
argument when it is already bound
-r keyseq Remove the binding for KEYSEQ.
For further information see help bind
in the bash command line
Best Answer
To exec or not to exec
But not every command is the name of a program to execute. So often there is no
exec
call involved. The key distinction is that in contrast to( cmd1; cmd2; )
, you don't get another shell process. Or perhaps more correctly, the shell will only fork to execute child programs, not to execute shell processes.Strange prompt
As other answers have pointed out, your command was incomplete. So the command line belonged to bash itself, which was waiting for the end of your group.
Uses
… as opposed to subshell grouping
The most prominent example is setting variables in that subcommand. Thy this:
This will print
So although you set
foo=3
inside one group, that group was executed in a subshell and its settings didn't propagate to the parent.Another thing worth considering is current working directory.
{ cd foo; make; }
will leave you in directoryfoo
whereas( cd foo; make; )
will not alter the current working directory of your main shell.… as opposed to ungrouped commands
The grouping is mostly useful if you have other code outside, e.g. conditionals
or redirections