I currently created a few snippets for the use in RStudio. In one snippet I also saved a password including a $ sign. But this $ and the letter follwing it is not shown when I use the snippet.
Here comes an example:
snippet test
pwd="dFKm$T#QUA1Uly#"
When I use the snippet I get the following output in my script:
pwd="dFKm#QUA1Uly#"
So th $T in the password string is missing. Any ideas why this happens and how i can solve this issue?
Related
I want to add an ssh-key generated in a shell script to my gcp project metadata. The problem is, that I don't really know how to format the generated key to be in the format which is need for the project metadata. The ssh-key I have looks like this:
ssh-rsa AAAAB3.... username
The format that is stated in the documentation is this:
username:ssh-rsa AAAAB3....
Is there a way to reformat the key within my shell script using echo and cat?
My best try is this: echo $USERNAME:$(cat ~/.ssh/id_rsa.pub), but this still leaves the trailing username at the end.
Assuming you are using bash, this should do the trick:
# Use the following line to read the key from a file
# KEY_WITH_USERNAME=$(cat ~/.ssh/id_rsa.pub)
KEY_WITH_USERNAME="ssh-rsa AAAAB3.... username"
USERNAME=${KEY_WITH_USERNAME##* }
KEY_WITHOUT_USERNAME=${KEY_WITH_USERNAME%"$USERNAME"}
echo $USERNAME:$KEY_WITHOUT_USERNAME
Outputs:
username:ssh-rsa AAAAB3....
See related questions about how to remove pre- or suffix from a string in Bash and how to split a string and get the final part.
I am creating an IDE and I wish to implement jump to definition.
I found the perfect tool for it: ctags (https://github.com/universal-ctags/ctags)
Now the only problem is that the tags file that ctags create looks something like this:
QLineNumberArea 2point56mb.py /^class QLineNumberArea(QWidget):$/;" c
I understand the format: {tagname}Tab{tagfile}Tab{tagaddress}
So from what I understand: tagname: QLineNumberArea, tagfile: 2point56mb.py and tagaddress: /^class QLineNumberArea(QWidget):$/;" c`
The tagaddress looks like gibberish but it's a vim/ex editor command that takes you to the definition.
Now from what I read on this website: https://github.com/cztchoice/ctags/wiki/Tag-Format
Under Security it states:
Specifically, these two Ex commands are allowed:
A decimal line number:
89
A search command. It is a regular expression pattern, as used by Vi, enclosed in // or ??:
/^int c;$/
?main()?
Now here comes the problem:
I need my tags file to have a line number, instead of the search command.
I tried looking the documentation for ctags (http://docs.ctags.io/en/latest/) but I couldn't find anything that would help me.
Does anyone know how make ctags give tag addresses as a line number, rather than a search command?
That documentation is only for the changes introduced by universal ctags. What you're looking for is the documentation for exuberant ctags:
−−excmd=type
Determines the type of EX command used to locate tags in the source file. [Ignored in etags mode]
Which can also be achieved with -n.
I have a problem reading ASCII-Files into Origin9.1. My ASCII-File looks like below: (note that I have 1 space before , 2 spaces between and 1 space after the numbers)
C:\amiX_TimeHist_P1.dat:
0,19325E-02 0,10000E+00
0,97679E-11 0,99997E-11
0,19769E+10 0,10025E+00
0,39169E+00 0,11636E+00
0,47918E+00 0,13156E+00
later I want to do the following with a scr-File but for now I write the following in Origin2015 in the Script-LabTalk-window:
open -w C:\amiX_TimeHist_P1.dat;
That command works but the numbers I get are in a wrong format:
When I read the file with the Import-wizzard or with ASCII-Import I can choose several options to fit the numbers correctly in the my columns. But this has to be done automatically.
Is there a way to read an ASCII-File uncluding setting parameters when using a script?
Instead of open you should use impASC to import ASCII data. Then you can specify some options to the command. In your case the following should work:
impASC fname:=C:\amiX_TimeHist_P1.dat options.FileStruct.DataStruct:=2 options.FileStruct.MultipleDelimiters:=" " options.FileStruct.NumericSeparator:=1;
If you just type impASC in your script window, in the following dialog box you can edit the import options and display the corresponding skript command.
I'm using the latest stable version of Smarty and can't get this string to work. I've looked at other questions for solution to do this but none seem to work.
This is a template file (TPL), and doesn't contain any PHP at all. Note that the TPL file is compiled to a PHP script and then sent to the browser. It's not a PHP file.
Current code:
'foo{$bar}'
which outputs as:
'foo{$bar}'
instead of the value of $bar.
What am I doing wrong?
If you use any variables within text you have to use double-quotes " instead of single quotation marks '. Text within single quotation marks is not parsed for variables in PHP.
I have to ls command to get the details of certain types of files. The file name has a specific format. The first two words followed by the date on which the file was generated
e.g.:
Report_execution_032916.pdf
Report_execution_033016.pdf
Word summary can also come in place of report.
e.g.:
Summary_execution_032916.pdf
Hence in my shell script I put these line of codes
DATE=`date +%m%d%y`
Model=Report
file=`ls ${Model}_execution_*${DATE}_*.pdf`
But the value of Model always gets resolved to 'REPORT' and hence I get:
ls: cannot access REPORT_execution_*032916_*.pdf: No such file or directory
I am stuck at how the resolution of Model is happening here.
I can't reproduce the exact code here. Hence I have changed some variable names. Initially I had used the variable name type instead of Model. But Model is the on which I use in my actual code
You've changed your script to use Model=Report and ${Model} and you've said you have typeset -u Model in your script. The -u option to the typeset command (instead of declare — they're synonyms) means "convert the strings assigned to all upper-case".
-u When the variable is assigned a value, all lower-case characters are converted to upper-case. The lower-case attribute is disabled.
That explains the upper-case REPORT in the variable expansion. You can demonstrate by writing:
Model=Report
echo "Model=[${Model}]"
It would echo Model=[REPORT] because of the typeset -u Model.
Don't use the -u option if you don't want it.
You should probably fix your glob expression too:
file=$(ls ${Model}_execution_*${DATE}*.pdf)
Using $(…) instead of backticks is generally a good idea.
And, as a general point, learn how to Debug a Bash Script and always provide an MCVE (How to create a Minimal, Complete, and Verifiable Example?) so that we can see what your problem is more easily.
Some things to look at:
type is usually a reserved word, though it won't break your script, I suggest you to change that variable name to something else.
You are missing an $ before {DATE}, and you have an extra _ after it. If the date is the last part of the name, then there's no point in having an * at the end either. The file definition should be:
file=`ls ${type}_execution_*${DATE}.pdf`
Try debugging your code by parts: instead of doing an ls, do an echo of each variable, see what comes out, and trace the problem back to its origin.
As #DevSolar pointed out you may have problems parsing the output of ls.
As a workaround
ls | grep `date +%m%d%y` | grep "_execution_" | grep -E 'Report|Summary'
filters the ls output afterwards.
touch 'Summary_execution_032916.pdf'
DATE=`date +%m%d%y`
Model=Summary
file=`ls ${Model}_execution_*${DATE}*.pdf`
worked just fine on
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Part of question:
But the value of Model always gets resolved to 'REPORT' and hence I get:
This is due to the fact that in your script you have exported Model=Report
Part of question:
ls: cannot access REPORT_execution_*032916_*.pdf: No such file or directory
No such file our directory issue is due to the additional "_" and additional "*"s that you have put in your 3rd line.
Remove it and the error will be gone. Though, Model will still resolve to Report
Original 3rd line :
file=`ls ${Model}_execution_*${DATE}_*.pdf`
Change it to
file=`ls ${Model}_execution_${DATE}.pdf`
Above change will resolve the could not found issue.
Part of question
I am stuck at how the resolution of Model is happening here.
I am not sure what you are trying to achieve, but if you are trying to populate the file parameter with file name with anything_exection_someDate.pdf, then you can write your script as
DATE=`date +%m%d%y`
file=`ls *_execution_${DATE}.pdf`
If you echo the value of file you will get
Report_execution_032916.pdf Summary_execution_032916.pdf
as the answer
There were some other scripts which were invoked before the control reaches the line of codes which I mentioned in the question. In one such script there is a code
typeset -u Model
This sets the value of the variable model always to uppercase which was the reason this error was thrown
ls: cannot access REPORT_execution_032916_.pdf: No such file or directory
I am sorry that
i couldn't provide a minimal,complete and verifiable code