There are quite a few commands that take subcommands (e.g., git, or task from taskwarrior). Sometimes I have a terminal window that is devoted entirely to running this command with varying subcommands. What I wish is that I would not always need to type the main command. Let me explain this with an example from taskwarrior (a “todo list manager”):  $ task add proj:job +hard Refactor the API -- Add task to project 'job' tagged 'hard' $ task proj:job +easy add prio:H Fix typo in README -- Tag is 'easy', priority 'high' $ task proj:job next -- List tasks in project 'job', ordered by 'urgency'   As you can see, task is quite flexible in where the subcommand (e.g., add or next) can be placed. Now, if I'm working on a certain project (say 'job') then I would like to drill down. Something like:  $ CONTEXT="task proj:job" [task proj:job] $ add +hard Refactor the API [task proj:job] $ +easy add prio:H Fix typo in README [task proj:job] $ next   The title of this question is very broad (suggesting you might want to run a sed-script over your command before executing it). However, I would be very happy with one of the following:   I can set some variable (like CONTEXT in the example) whose value is prepended to every command, before running it. Alternatively, and even better, the value of CONTEXT could be filled in on the command line before I start typing my commands. In that way, I can occasionaly hit backspace or Ctrl-U if I want to run a command outside of my context.      Q. Is there a shell (preferably bash-like, for example zsh) that has the described feature?
123780
I am trying to create a program which require such feature. The flow will be like:   User enter a bash command User hit the enter My script will get command, current directory,.. as variables. Program can optionally modify the command. Modified command will get executed normally.   Is there any way to do this?  Note: I need this for my personal use, I am not going to distribute this program.
108554
I recently asked this question about adding a shell script to Dash:      It worked perfectly.  Follow-up question:  How can I pass command-line arguments through Dash?  Example:  In this case, my dash command is named "Panel".  The script panels my screen with 8 terminals.  Here's an example of the usage:  panel             # Tile the screen with 8 terminal windows. panel --left      # Tile the left side with 4 terminals panel --right     # Tile the right side with 4 terminals   And so on.  How can I pass arguments like --left or --right through Dash?  Ideally I'd like to have this workflow:   Press the SUPER key Type panel --left (for example) Dash goes away and the left side is paneled.   Right now it runs the right script, but ignores --left.   Tips?
62738
Let's say I compile the following file with pdflatex -shell-escape test.tex:   \documentclass{minimal}  \begin{document}  File listing is:  \immediate\write18{ls /usr}  \end{document}   This will send the output of the command ls /usr to report/log of pdflatex (primarily to stdout).   There are then two cases I'd like to utilize:    The output of ls /usr being included directly in the document (LaTeX stream). The output of ls /usr becoming the contents of a \newcommand (by this I mean, that I'd like the script to be executed when the \newcommand is executed first - and upon subsequent calls to the new command, the shell code should not be executed anew).    I have read through , but I'm not sure if this "pipe input" can be applied to \newcommand.   I have also read through  - and it seems that Tex' file I/O should be used; but I'm quite disliking the fact that I'd still have to redirect the script output (actually, in this case, the ls /usr output) to a file, and then read it in, to have it as contents of a command.   So, is there an easier way to achieve what I'd want (hopefully, illustrated through an example based on the above code)?     EDIT: Ehm, I should have asked one more question earlier :) I'll try with an edit here, although it will probably get missed .. :)   I originally asked for a \newcommand that will execute shell code only upon its definition (i.e., in a sense it is "cached"); and the answer from @egreg does exactly that. But then - would it be possible to have a different \newcommand definition, such that each time this newcommand is called, the shell command is executed anew? I.e. executing something like \@@input|"cat tempfile" (which cannot be executed as such), where tempfile changes between calls?
33061
I'd like to run a particular application (let's call it foo) from the command line, but I don't want it holding up the terminal, putting any junk in the terminal from its output or error streams, and also want it to keep running even if I close said terminal. In Bash, I can do that using (foo &amp;&gt;/dev/null &amp;), but I don't know how I would do that in Windows shell. Could someone please help me?
12192
By typing a manually specified command in terminal I want to execute some other command.  How could add an alias to a command? Can i do that with the help of the terminal or should I edit some kind of file?
102186
Hi I have a bash script that intend to run via watch ./script.sh  It's to debug a cooling problem with my laptop, however the script I wrote isn't working as intended.  I'm quite new to bash scripting so I'm sure its something simple.  I have a line in my script that has a nested command substitution but the inner command doesn't appear to work or at least it looks like the inner command doesn't know the value of $i. Any help appreciated.  here's the script:  echo "THERMAL ZONE 2:" echo "Cur Temp: $(cat /sys/class/thermal/thermal_zone2/temp)"  for i in {2..7} do echo "cooling_device$i STATE: $(cat /sys/class/thermal/thermal_zone2/cdev$i/cur_state) TRIP POINT TEMP: $(cat /sys/class/thermal/thermal_zone2/trip_point_$(cat /sys/class/thermal/thermal_zone2/cdev$i_trip_point)_temp)" done   and heres the output:  THERMAL ZONE 2: Cur Temp: 43000 cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device2 STATE: 1 TRIP POINT TEMP:  cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device3 STATE: 1 TRIP POINT TEMP:  cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device4 STATE: 0 TRIP POINT TEMP:  cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device5 STATE: 0 TRIP POINT TEMP:  cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device6 STATE: 0 TRIP POINT TEMP:  cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory cooling_device7 STATE: 0 TRIP POINT TEMP:
99452
I'm quite happy hacking TeX macros and cobbling together bits and pieces from different style files to suit my own ends, but I have a suspicion that my resulting hacks are not quite as elegant as they could be.  In particular, with regard to when to expand and when not to expand macros.  A common occurrence for me is defining a meta-command that defines a whole slew of sub-commands.  So the names of the sub-commands will contain parameters depending on the parameter passed to the meta-command, and the contents of the sub-commands will also vary a little depending on what the meta-command got.  Often it won't be a direct substitution but rather a "if #1 is a do \this else do \that", but \this and \that need expansion at define time, not call time.  Here's a very simple example just involving direct substitution:  \def\cohtheory#1{ \expandafter\newcommand\expandafter{\csname #1func\endcsname}[1][*]{% \MakeUppercase{#1}^{##1}} }   Sometimes I worry that my commands are more complicated than they need be.  For example, if I want to call a command with two arguments and the arguments expand before the command, here's how I've coded it:  \expandafter   \expandafter   \expandafter   \command\expandafter             \expandafter             \expandafter               {\expandafter                 \argone                 \expandafter               }\expandafter               {\argtwo}   So I'm looking for guidance on when and how to control expansion in defining macros.  I strongly suspect that such cannot be given in a simple answer, so to make this a focussed question, let me phrase it thus:     Where's a good reference for writing TeX macros that includes advice on how to best deal with how to handle expansions?   Of course, if anyone can formulate some advice in short answer, I'd be only to happy to read it.  (Note: this was partially motivated by juannavarroperez's adaptation of my answer to  where over 20 \expandafters got condensed down to just 1!)
116894
I want to run a command before and after every single command that gets executed in a terminal (i.e. clear before and then reset). I want this to happen automatically and not with a short alias or similar.  I have looked into bashrc and /usr/share/bash-completion/bash_completion although the latter seems to be just for the auto completion feature with the Tab?   Where should I make my changes?
104641
I have a deployment script, it must add something to a user crontab (trigger a script that clean logs every XXX days), however this must only be done during the first deployment, or when it needs to be updated.  (I can run xxx.py deploy env or xxx.py update env)  so I have to do this:  Check if my cronJob already exist Put my cronJob if it does not already exist or update my cronjob if one of the parameter of the command is different   I don't see how to add/check/remove something to the crontab without using crontab -e or editing the crontab file (download it, rewrite it, re-upload it)  PS : this is a user specific cronjob, "webadmin" is going to do it and he should not use sudo to do it.
29570
I was curious how I would go about running multiple commands via shell script.  For example, just to try it out, I'd like to be able to connect a .desktop to a .sh that will run all the update codes so I don't have to type it out. I know how to execute a single command via a .sh, not multiple.  Any way?
50034
I've encountered a headache problem.  I want to execute mulitple commands in background, so I want to start them in bash one by one. It's easy to start one command in linux shell in background, just like this:  myCommand &amp;   It's also easy to start multiple commands, just like this:  myCommand1 &amp;&amp; myCommand2   or  myCommand1 ; myCommand2   But if I want to run multiple commands in background, I tried the following command format, but failed:  myCommand1 &amp; &amp;&amp; myCommand2 &amp;   or   myCommand1 &amp; ; myCommand2 &amp;   Both formats fail. How can I run multiple commands which have &amp; in one command line?
45140
I want players to be able to click text to run an OP command even if that player is not an OP. For example something like:  Console: Do you want to enable Fly? [If you do, Please click here]  *Player1 clicks that text*  Console: /fly Player1   Is something like this possible?
66272
I'm a web developer. When I want to start working, always i'm executing some command on terminal. For example:  sudo service apache2 start sudo service mysql start sublime   For speed up this process, I create a .sh file which contain these commands.   Now, when I want to start working, I'm just executing this .sh file and all services (mysql, apache2 etc.) starting.   Is it possible to create a custom command for this? For example if I type sudo start-working to terminal, it will execute these commands
5204
I recently learned about , but am having trouble making it work with relatively sophisticated commands. For example, I would like to ask watch to run the following command on zsh every three seconds*: for x in `command_1 | grep keyword | cut -d' ' -f1`; do command_2 &quot;word[word=number]&quot; $x; done  as you can see the line above includes single quotes, double quotes, among other special characters. So I tried: watch -n 3 &quot;for x in `my_command | grep keyword | cut -d' ' -f1`; do command2 &quot;rusage[mem=7000]&quot; $x; done&quot;  but then I got:  no matches found for x in !@#$# ....; done  I tried other combinations without success. Here's one of those attempts: watch -n 3 &quot;for x in $(bjobs -w | grep pre_seg | cut -d' ' -f1); do bmod -R &quot;rusage[mem=7000]&quot; $x; done&quot;  which also results in a similar error. Any ideas how to make this work?  *I would also be intersted in solutions that work on bash
120521
As a developer, I often have the need to open a command prompt for various purposes. For example, I use iisreset to restart my local web server.  I typically open the command window in one of two ways:   Press Win, type "cmd" and press Enter While in Explorer, hold Shift and right click on a folder, and choose "Open command window here"   However, when I open the command window in either of these ways, I do not have the full administrator privileges that I feel I am entitled to.    In order to run administrator-only applications, I have to open the command line in this relatively laborious way:   Press Win, type "cmd" Wait for the menu to populate Lift hand off the keyboard and put it on the mouse Right click the "cmd.exe" menu item Choose "Run as administrator"   This is unacceptable for several reasons:   The window always opens in C:\windows\system32, rather than my Users directory (as in approved technique 1) or the folder I want to be in (as in approved technique 2). So I often have to change directories to get where I want to go. This process is several milliseconds slower than either of my preferred methods. Performed several times a day, every day for the remainder of my career, it adds up to about ten days of lost time spent clicking and waiting and directory changing. As a programmer, performing a pointless robotic task causes me great emotional pain. As a programmer, lifting my hand is a strenuous task that causes me great physical pain.   That is why I am looking for a one-and-done solution that will let approved techniques 1 &amp; 2 open administrator command prompts.  Many programs let you permanently change their default privilege level from the Properties menu. Command Prompt is not one of those programs.    How do I make the command window run as administrator by default (even when using the "Open command window here" context menu option)?
120458
I have recently discovered that if we press Ctrl+X Ctrl+E, bash opens the current command in an editor (set in $VISUAL or $EDITOR) and executes it when the editor is closed. But it doesen't seem to be documented in the man pages.
51376
For I school project, I have to implement a shell/terminal app. But I am wondering how are command line options parsed, because it appears abit weird to be. For example for the command paste (and I believe other utilities behave similarly)  [jiewmeng@JM tmp]$ paste --help Usage: paste [OPTION]... [FILE]...   Behavior when combining multiple options into one  [jiewmeng@JM tmp]$ paste -ds file1 file1 xxx file1 d aaws dafd a   Here it appears options are just ignored ...   [jiewmeng@JM tmp]$ paste -sd file1   It behaves the same as paste -, waiting for stdin. But when its valid combination  [jiewmeng@JM tmp]$ paste -sd. file1 file1 xxx.file1.d aaws dafd a   It works. Shouldn't the invalid one give an error instead of waiting for stdin?  [jiewmeng@JM tmp]$ paste -d paste: option requires an argument -- 'd' Try 'paste --help' for more information.   Ok, makes sense d requires an argument, but ...   [jiewmeng@JM tmp]$ paste -d file1   ... waits for stdin. why?