Search Results

Search: Posts Made By: johnprogrammer
3,881
Posted By johnprogrammer
You are right, my mistake.
You are right, my mistake.
3,881
Posted By johnprogrammer
There are logical errors in the code. For...
There are logical errors in the code.

For example

for dir in /home/cmccabe/medex.logs/ponc/*/ ; do

if [ -d "$dir" ] ; then
run="$(basename "$dir")"
fi


$run is always *
...
3,881
Posted By johnprogrammer
I think I finished your program. Test it, and...
I think I finished your program. Test it, and tell us if it works.


#!/bin/sh

# POSIX shell compliant.

# grab run directory.
set -xv

for dir in /home/cmccabe/medex.logs/ponc/*/ ; do

...
3,881
Posted By johnprogrammer
Your code typo corrected. It is POSIX shell...
Your code typo corrected. It is POSIX shell compliant, and it works with Bash too.


#!/bin/sh

# POSIX shell compliant.

# grab run directory.
set -xv

for dir in...
7,153
Posted By johnprogrammer
Shutdown is a system-wide action, and requires...
Shutdown is a system-wide action, and requires root privileges in some UNIX systems (macOS included).

This means, if you want to have shutdown as an option in a script, you will need to give the...
7,276
Posted By johnprogrammer
Thank you. Those were what I...
Thank you.




Those were what I understood.




Yes, I knew that, but I considered my answer as a good starting point.




This is important, and you are right. I thought a few times...
7,730
Posted By johnprogrammer
It is a macOS thing. You must right click on the...
It is a macOS thing. You must right click on the Terminal icon on the Dock, and select Quit.

See the screenshot attached.
7,276
Posted By johnprogrammer
The following code works: #!/bin/sh ...
The following code works:


#!/bin/sh

# POSIX shell compliant.

grep -i "httpd" input.txt | sed "s/ //" | sed "s/ //" |sed "s/(/ (/"

exit 0
3,238
Posted By johnprogrammer
Here is POSIX shell compliant code, that returns...
Here is POSIX shell compliant code, that returns the full path of a file or directory.


#!/bin/sh

# FullPath subroutine, version 1.0, POSIX shell compliant.

# Copyright © 2019 Ioannis...
5,432
Posted By johnprogrammer
What does ${x} mean?
In POSIX shell, what is the difference between $x and ${x} ?


Example:

#!/bin/sh

x=1

echo $x
echo ${x}

exit 0


They both print "1".
1,931
Posted By johnprogrammer
I completed the code: #!/bin/sh # Code...
I completed the code:

#!/bin/sh

# Code is POSIX compliant

tput clear

currentDate="$(date -R)"


counter=0

for word in $currentDate
do

# We ignore the day of the week.
if [...
1,931
Posted By johnprogrammer
I am new to shell programming, here is what I...
I am new to shell programming, here is what I did.


#!/bin/sh

# Code is POSIX compliant


currentDate="$(date -R)"


counter=0

for word in $currentDate
do

# We ignore the day of...
1,773
Posted By johnprogrammer
Thank you for your reply. The code is not...
Thank you for your reply.

The code is not POSIX shell compliant. POSIX shell has not arrays, and not this kind of for loop.

I am in the half of my introductory POSIX shell book, so there are a...
1,773
Posted By johnprogrammer
Yes you are right. When the...
Yes you are right.






When the shell script starts, both arg1 and arg2 have the same value.

So I use the counter with value 0, to determine this case, and advance the second for-loop to...
1,773
Posted By johnprogrammer
The POSIX shell code detects if there are two or...
The POSIX shell code detects if there are two or more, same command line arguments to the script.


An example with C++03.

Assuming we have a vector (array) with some strings:


#include...
1,773
Posted By johnprogrammer
I found the issue, the second code fragment has a...
I found the issue, the second code fragment has a logical mistake.
1,773
Posted By johnprogrammer
Why the results of these two POSIX shell code fragments, are not the same?
Code 1:



#!/bin/sh

for arg1 in "$@"
do
counter=0

for arg2 in "$@"
do

if [ "$arg2" = "$arg1" ] && [ $counter -eq 0 ]
then
counter=$((counter+1))

...
7,928
Posted By johnprogrammer
Equivalent to let command in POSIX shell
Hi all,

I am learning POSIX shell programming, and the book I read, uses the let command for integer arithmetic.

I have downloaded and use the shellcheck program on Linux.

This programs...
Showing results 1 to 18 of 18

 
All times are GMT -4. The time now is 12:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy