1 |
On 06/12/2016 11:54 AM, Andrew Lowe wrote: |
2 |
> On 06/12/16 23:07, Andrew Lowe wrote: |
3 |
>> On 06/12/16 22:43, Alan McKinnon wrote: |
4 |
>>> On 12/06/2016 16:33, Nico Verrijdt wrote: |
5 |
>>>> Hi Andrew, |
6 |
>>>> |
7 |
>>>> 2016-06-12 16:26 GMT+02:00 Andrew Lowe <agl@×××××××.au |
8 |
>>>> <mailto:agl@×××××××.au>>: |
9 |
>>>> |
10 |
>>>> Hi all, |
11 |
>>>> A bit off topic here, but there are plenty of people who |
12 |
>>>> seem to know their shells back to front so here goes. |
13 |
>>>> |
14 |
>>>> I have set up a Win32 based development environment, |
15 |
>>>> bash/cc/ls/etc/etc, for 1st year Engineering students who have to |
16 |
>>>> learn C on a command line. It's fine for me to remember to put |
17 |
>>>> the & |
18 |
>>>> at the end of the command when I fire up the editor but for them, |
19 |
>>>> it's major angst. |
20 |
>>>> |
21 |
>>>> The first thing that comes to mind is an alias. Just off |
22 |
>>>> the top of my head I tried: |
23 |
>>>> |
24 |
>>>> alias "npp=npp %1 &" |
25 |
>>>> |
26 |
>>>> Shouldn't this be: alias npp="npp %1 &" ? |
27 |
>>>> |
28 |
>>>> |
29 |
>>>> npp being the editor, but that didn't work. Is an alias the |
30 |
>>>> best/easiest way to do this and if so, what would the syntax be, or |
31 |
>>>> is there a better way? |
32 |
>>>> |
33 |
>>>> Any thoughts, greatly appreciated, |
34 |
>>>> |
35 |
>>>> Andrew |
36 |
>>>> |
37 |
>>>> |
38 |
>>>> Hope this helps, |
39 |
>>>> Nico |
40 |
>>> |
41 |
>>> |
42 |
>>> Or just tell them to remember to add the & at the end. |
43 |
>>> With an alias what will they do when they don't want it? |
44 |
>>> |
45 |
>>> Or look at it this way: |
46 |
>>> |
47 |
>>> It's syntax, it's important. C is probably more syntax-critical than any |
48 |
>>> other language around (binds to the right, anyone?) so what's the |
49 |
>>> problem with requiring correct syntax on the command line as well? |
50 |
>>> |
51 |
>>> Obligatory disclaimer: I've recently had a bellyache full of dumb people |
52 |
>>> who insist I put code when a human (themselves) belongs... |
53 |
>>> |
54 |
>> Yes, I agree BUT, this is a "half subject" in a common first year of |
55 |
>> an Engineering degree. These are people who will become |
56 |
>> Civil/Mechanical/Electrical/Chemical Engineers and they have no desire |
57 |
>> to learn programming. To put it bluntly, all they are interested in is |
58 |
>> their car, getting drunk and trying to get a root - the order may vary, |
59 |
>> but that is the top three priorities. Anything else is just too much to |
60 |
>> think about. |
61 |
>> |
62 |
>> In reality, I'm doing this to make my life easier. As much as I tell |
63 |
>> them to do something, write up documents that tell them what to do and |
64 |
>> reiterate what they have to do, I still get the question "It's broken, |
65 |
>> it won't do as I want...." |
66 |
>> |
67 |
>> Andrew |
68 |
>> |
69 |
>> p.s. Nico's point was a typo on my part in the email. |
70 |
>> |
71 |
> |
72 |
> Simple answer to this which a single google search found. You CAN'T |
73 |
> pass parameters to an alias under Bash. You need to do a function. A |
74 |
> simple function of: |
75 |
> |
76 |
> npp() |
77 |
> { |
78 |
> npp $1 & |
79 |
> } |
80 |
> |
81 |
> was all I needed. |
82 |
> |
83 |
> Andrew |
84 |
> |
85 |
> |
86 |
|
87 |
A better function for the same (that also doesn't loop forever because |
88 |
the function might be calling itself): |
89 |
|
90 |
npp() { |
91 |
command npp "$@" & |
92 |
} |
93 |
|
94 |
This allows any number of arguments to be passed, instead of "exactly |
95 |
one" and allows filenames containing spaces, etc. to be passed correctly. |
96 |
|
97 |
-- |
98 |
Jonathan Callen |