Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a shell script that uses an array. The script cycle through the entries of the array but for some reason the first and last entry has a problem.
The array:
Queue_Names=( CLQueue DLQ ExpiryQueue )
The for Loop:
for i in “${Queue_Names[#]}”
do
#do stuff
done
I can see in the console and shows that for the first entry it shows: �CLQueue.
The last entry shows: ExpiryQueue�
I'm guessing these are markers to know the start and end of the array. Unfortunately it is interfering with the functionality of the script. I use these Queue names to search for something and it fails to find it because of the added character. How do I get rid of them or is there a code change I do to avoid the problem?
“${Queue_Names[#]}” is not "${Queue_Names[#]}", because “” is not "".
"Smart quotes" aren't recognized as quotes at all in bash; thus, the effect is the same as if the expansion had been unquoted -- string-splitting and glob-expansion on array contents -- with the literal "quotes" grafted around the start and end characters.
You need to use real quotes -- "" -- not opening/closing "smart quotes" created by some word processing software or corporate email tools.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a script that writes about 20 numbers line by line to a file during processing.
When the script starts again, it reads from this file with this code
declare -a sedum
i=0
while read -r line
do
sedum[$i]=$line
i=$(( $i + 1 ))
done < $f_sday
f_sday contains the filename. When I call the script from comand line it always works fine and reads the complete content of the file.
But when the script is called in a cronjob it reads only two or three values
I know that from cron it might not be the same environment but I can't see any environmental dependency here.
I tried mapfile at first, but that read only two of the twenty values.
Any idea what I am missing here?
Stupid me.
I did not control the working path (cron starts in $HOME), so the script was working on the wrong file.
Thanks for the set -x hint. That led me on the right path!
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I use fgetc to read characters from a file and it reads something strange.
I have this in the txt file:
But when i look at the file info it shows this:
and fgetc actually reads the { as first character of the file instead of S.
I tried to change the file extension to rtf,txt, no extension but same result.
Any ideas how to fix this?
Looks like you wrote the file in some sort of editor that stores its metadata at the beginning of the file. Try recreating the file with a more basic editor that does just text editing. Or from the command line echo "my file contents" > myfilename.txt.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I made a program which takes numbers from the command line and adds them, the program is supposed to print an error if something else than a number is written, but when it reads > or < it creates text files with the results or rewrites on an already existing text file, if it doesn't exist it just stops without even running the code, is there a way to stop this from happening and read it just like another array?
Here is an example of the error
$ ./a +24 < 5
bash: 5: no such file or directory
That's not your program - that's the shell file I/O redirection. If you want your program to see the < or >, escape them appropriately:
./a +24 \<5
As ths others have said, it is not your program acting up, but the command line shell uses < and > as input/output redirection operators. You could escape them with backslashes.
But rather than forcing the users to escape each < and > (and possibly some other special characters like $ and the parentheses), you can quote the whole command line:
./a '1 < 24'
The whole command now is in argv[1]. You still have to parse it. As a bonus, there is no need to insert annoying spaces between the tokens anymore:
./a '1<24'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'd like to edit multiple (~2000) txt files in Notepad ++. To be more specific: I'd like to narrow the entire text of into a column with newlines.
Like so:
into:
Of course it is not as simple, because the Text is dynamic and contains brackets for certain terms that will later help a search engine (Those will however not become unfunctional when separated with a newline which comes in very handy).
I found out that I can do so easily with the Line Operation "Split Line" in the "Edit" tab. Now I just need to do it with the rest of the files. I wonder if that can be automated? As it is not a macro it could be kind of tricky. Another thing I thought of was using a RegEx in the "Find in Files" option. Something like "find n characters with n spaces in between them" then "replace the exact same chars with the same chars but add a newline at the end".
Or "make a newline every 7 spaces".
Not sure if that is a viable approach, though.
Im curious about what you think about this. Any Suggestions?
In Find in Files, you may use
Find What: (?:^|\G)(\S*(?:\h+\S+){7})\h*
Replace With: $1\n
Do not forget to check the Regular expression radio button at the bottom.
Pattern details:
(?:^|\G) - either start of line or the end of the last successful match
(\S*(?:\h+\S+){7}) - Group 1 later referenced to with $1 backreference in the replacement pattern, capturing 0+ non-whitespace symbols, followed with exactly 7 sequences of 1+ horizontal whitespaces and 1+ non-whitespaces
\h* - zero or more horizontal whitespaces
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using following code to create a new file cat15 using cat command in UNIX
# cat > cat15
this command adds a new file cat15 in root directory and whatever I type after this command is being stored into the file created. But I am not able to exit from this editor.
In other word, I am not getting Shell prompt symbol #
The cat command reads from STDIN if you don't specify a filename. It continues to do this until it receives an EOF or is killed. You can send an EOF and get your terminal back by typing <ctrl>+d.
What people generally do is to either use
touch filename
or
echo -n > filename
to create an empty file. As Charles correctly notes below, "echo -n" is not always a good idea (though you can usually count on it under "popular" Linux distros); I'd strongly suggest just using touch.
If you just want to create an empty file, regardless of whether one existed or not, you can just use ">" like this:
> cat15
It will clobber anything that already exists by that name.