commands like 'stack exec — yesod --help' - yesod

In the Yesod book
https://www.yesodweb.com/book/scaffolding-and-the-site-template
commands are given like
'stack exec — yesod --help'
and
'stack exec — yesod devel'
but what is that '—' symbol (I can only copy / paste it), and what is its meaning?

It is called an em dash (and how to create it on your keyboard). In the case where it is being used with Yesod, it is somewhat unclear to me if using the em dash was on purpose or not. Some programs (like Microsoft Word) automatically convert two hyphens (--) into an em dash. I think this may be what happened in this case - because over at GitHub there is a post where the command stack exec -- yesod devel is used. This would be more consistent with typical command line usage of hyphens - the single and double hyphens are supposed to have specific/standard meaning when used in command line utilities.

Related

What does it mean by the last dash in $(gcc -xc++ -E -v -)? [duplicate]

Examples:
Create an ISO image and burn it directly to a CD.
mkisofs -V Photos -r /home/vivek/photos | cdrecord -v dev=/dev/dvdrw -
Change to the previous directory.
cd -
Listen on port 12345 and untar data sent to it.
nc -l -p 12345 | tar xvzf -
What is the purpose of the dash and how do I use it?
If you mean the naked - at the end of the tar command, that's common on many commands that want to use a file.
It allows you to specify standard input or output rather than an actual file name.
That's the case for your first and third example. For example, the cdrecord command is taking standard input (the ISO image stream produced by mkisofs) and writing it directly to /dev/dvdrw.
With the cd command, every time you change directory, it stores the directory you came from. If you do cd with the special - "directory name", it uses that remembered directory instead of a real one. You can easily switch between two directories quite quickly by using that.
Other commands may treat - as a different special value.
It's not magic. Some commands interpret - as the user wanting to read from stdin or write to stdout; there is nothing special about it to the shell.
- means exactly what each command wants it to mean. There are several common conventions, and you've seen examples of most of them in other answers, but none of them are 100% universal.
There is nothing magic about the - character as far as the shell is concerned (except that the shell itself, and some of its built-in commands like cd and echo, use it in conventional ways). Some characters, like \, ', and ", are "magical", having special meanings wherever they appear. These are "shell metacharacters". - is not like that.
To see how a given command uses -, read the documentation for that command.
It means to use the program's standard input stream.
In the case of cd, it means something different: change to the prior working directory.
The magic is in the convention. For millennia, people have used '-' to distinguish options from arguments, and have used '-' in a filename to mean either stdin or stdout, as appropriate. Do not underestimate the power of convention!

Using command line arguments to extract from txt file and run specific classes in C++

I'm working on a project that needs to be run with either of the following commands:
./project.exe -Stack < [filename]
./project.exe -Queue < [filename]
I am wondering why there is a - in front of both Stack and Queue and why the filename is preceded by < and is in brackets.
The purpose of this format is to tell the program to either run using a stack class or run using a queue class. I will also need to extract the information from the text file mentioned in the command line.
I am familiar with general command line arguments and how to use them, but I have never seen this notation before and can't find any clear explanations.
The dash for the options are simply a common convention. Usually with modern command-line programs one uses double-dash for so-called long options (like e.g. --stack) and single dash for short options (e.g. -s).
Many existing argument parsers, like the Linux getopt_long function, actually requires the single or double dashes for short and long options to be recognized as such.
The < is file redirection. It tells the shell to redirect the programs standard input from the file. Inside the program you can read from standard input (std::cin) and it will be automatically reading from the file. This redirection is handled entirely by the shell.

Detecting semicolon as command line argument in linux

I am trying to run a C++ application where I am passing some command line arguments to it as follows:
./startServer -ip 10.78.242.4 tcpip{ldap=no;port=2435}
The application is getting crashed because it is not able to get the correct port. Searching over the web, I found that ";" is treated an end of command character (Semicolon on command line in linux) so everything after that is getting ignored. I also understand the putting it inside the quotes will work fine. However, I do not want to force this restriction of putting the arguments in the quotes on the users. So, I want to know is there a way I can process the ";" character with the argv array?
The semicolon separates two commands so your command line is equivalent to
./startServer -ip 10.78.242.4 tcpip{ldap=no
port=2435}
Your application will never know anything about either the semi colon or the second command, these will be completely handled by the shell. You need to escape the colon with a back slash or enclose it in quotes. Other characters which may cause similar issues include: $,\-#`'":*?()&|
Complex strings are much easier to pass either from a file or through stdin.
You need to quote not only the ; but in the general case also the { and }:
./startServer -ip 10.78.242.4 'tcpip{ldap=no;port=2435}'
If your users are required to type in that complicated last argument, then they can also be made to quote it.

How-to Use Regex to locate _[a-z] and Replace with just the capital letter of the lower case letter

I've inherited a bunch of C++ files that need to have function and variable names changed to meet our new C++ coding 'standards'.
Like all C/C++ code, there are variables/functions such as my_new_function or My_Newer_Function...
The Java folks have forced a camel cap style on us, so what I want to do is search for any underscore and make the next letter capitalized and have the underscore removed, that is:
my_new_function becomes myNewFunction
and
My_Newer_Function becomes MyNewerFunction
also, if the name has a number in it such as my_8th, it just removes the '_' to become my8th. This should probably be a separate regex.
I have some general knowledge of regex but this one has stumped me.. and with so many files and so little time, I have come to the beneficent gathering of the members of SO for help.
Thank you in advance.
Yes, I know, I should make the Java folks do this, but I just work here...
;-)
In my experience, if you try to change your code massively with a single command you risk to find exceptions (e.g., quoted text).
I suggest you to build a shell:
1. for each file
2. get the names of variables/functions
3. for each name apply the sed command to get its new-name
4. on the fly build a sed command to replace exactly each name with the new-name in the the file
…costly but secure…
You can do:
sed -r 's/_([a-z])/\U\1/g' file
See it

Doing a 'diff/st' and ignoring the first line if it matches a specific criterion

In a repository for a well known open source project, all files contain a version string with a timestamp as their first line:
<?php // $Id: index.php,v 1.201.2.10 2009-04-25 21:18:24 stronk7 Exp $
Even if I don't really understand why they do this - since the files are already under version control -, I have to live with this.
The main problem is that if I try to 'st' or 'diff' a release to get an idea of what was changed from the previous one, every single file contained in the repository is obviously marked as modified and the diffs become unreadable and unmanageable.
I'm wondering if there's a way to ignoring the first lines doing a diff/st when they match a regexp.
The project is under cvs - cvs, yes, you've read correctly - and included in a bigger mercurial repository.
I don't know about cvs, but with hg you can use any external diff tool with the bundled extdiff extension, and any modern tool should have the ability to let you ignore diffs that match certain patterns.
I swear by Beyond Compare, which allows arbitrary syntax definition.
kdiff3 has preprocessor commands that you can pipe the input through.
If you try
man diff
you'll find
--ignore-matching-lines=RE Ignore changes whose lines all match RE.
search "ignore matching lines" on the web gives examples :
diff --unified --recursive --new-file
--ignore-matching-lines='[$]Author.[$]'
--ignore-matching-lines='[$]Date.[$]' ...
(http://www.cygwin.com/ml/cygwin-apps/2005-01/msg00000.html)
Thus try :
diff --ignore-matching-lines='[<][?]php [/][/] [$]Id:'