hi ppl,
I have a basic doubt as to how shell treats strings.
e.g:given a line of data like this "5","6","45","77","89"
extracting the value from each field to a variable will conatin a string("5") or just the number?
If it conatins "5", how do we perform mathematical operations with that variable?
extracting the value from each field to a variable will conatin a string("5") or just the number?
I suppose your problem comes from your assumption that "strings" and "numbers" are different data types like in other programming languages.
But shells do NOT have data types as all. You can create a variable of type "integer", but it will be merely an ordinary string with only digits allowed. On the other hand you could create a string variable and use it as a number as long as its contains only characters which form a number. For instance the following lines are all syntactically legal:
Notice the second example. If i had tried to add some character to the $bar variable the shell would complain. This is because with "typeset -i" i declared that i want the variable only to contain characters which form an integer. This doesn't stop me from using the variable as a string like you see in the concatenation of $string.
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.
Please review the rules, which you agreed to when you registered, if you have not already done so.
More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.
Hi All,
I am trying to use below syntax to find ignore multiple locations while searching for a file.
find / -name "$serviceitem" ! -size 0 2>&1 |egrep -v "tmp|docker|WinSxS|Permission|HISTORY|alternatives|bearer11ssl|manifest"
I tried to assign all the ignore strings to one variable... (2 Replies)
Hi Experts,
I am writing a python script to grep string from file and display output in csv file as in attached screenshot
https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view
Input file(result_EPFT_config_device)
Below is the python script i have prepared as of... (1 Reply)
I want to create an array which can store the strings from the user input in shell script .
example :-
I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Hi together,
unfortunately I am not a shell script guru - the following might touch
the depths of awk, substr, split, regexps, where I am still fighting with - but as always the boss needs a fast solution :-(
So: I have the following USER/PASSWORD-installation-config-file, from where I want to... (10 Replies)
Hello All,
I have 2 files
1 ) source file eg
asasa 1.2.3.4 adfhsdfsdfasdf
zxzxzx 2.3.4.56 dsadasdasdsadasd
kjjkjkjk 30.3.4.5 asdsadsadsadsadsad
vxcvxcvx 1.2.3.4 qwewqewqeqweqwe
2) patern file
1.2.3.4 A
2.3.4.56 B
30.3.4.5 C
I need the source to be changed to
asasa A... (2 Replies)
Hi Folks,
The subject is my question:
Can we pass an array of strings from a Perl Program to a Shell Script?
Please provide some sample code.
Thanks
---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ----------
I got it.
Its here:... (0 Replies)
Hi,
I'm having a requirement where I need to call a C program from a shell script and return the value from the C program to shell script.
I refered a thread in this forum. But using that command in the code, it is throwing an error
clear_text_password=$(get_password)
Error: bash:... (24 Replies)
Hi,
Iam calling a C program from a Unix shell script. The (C) program reads encrypted username/password from a text file , decrypts and returns the decrypted string.
Is there any way i can return the decrypted string to Unix shell program.
My shell script uses the output of the program to... (11 Replies)