unix

Bash script check string for uppercase letter

亡梦爱人 提交于 2021-02-04 18:09:05
问题 I am trying to check a string for any Uppercase letter. my code shows NO UPPER for any input, may it be "sss", "Sss", "SSS" if [[ "$pass" =~ [^a-zA-Z0-9] ]] then echo "Upper found" else echo "no upper" fi 回答1: [^a-zA-Z0-9] means anything except for a-z , i.e. lowercase letters, A-Z , i.e. uppercase letters, and 0-9 , i.e. digits. sss , Sss , SSS all contain just letters, so they can't match. [[ $password =~ [A-Z] ]] is true if the password contains any uppercase letter. You should set LC_ALL

What is the difference between `sed -i -e` and `sed -ie`?

偶尔善良 提交于 2021-02-04 17:33:26
问题 What is the difference between sed -i -e and sed -ie ? It's not very clear from help sed --help -e script, --expression=script add the script to the commands to be executed In second case it creates some backup file? In general Unix utils do not permit to combine flags? Just an example to show what is happening: echo "bla" > 1.txt cat 1.txt bla sed -i -e 's:bla:blakva:g' 1.txt cat 1.txt blakva sed -ie 's:bla:blakva:g' 1.txt cat 1.txt blakvakva *Note: also 1.txte is created, containing cat 1

unix sort for 2 fields numeric order

心不动则不痛 提交于 2021-02-04 13:56:26
问题 I need to sort some data with unix sort but I can't figure exactly the right syntax, the data looks like 3.9.1 Step 10: 3.9.1 Step 20: 3.8.10 Step 20: 3.10.2 Step 10: 3.8.4 Step 90: 3.8.4 Step 100: 3.8.4 Step 10: I want to sort it using first the major number, then the step number, e.g. the data sorted above would look like. 3.8.4 Step 10: 3.8.4 Step 90: 3.8.4 Step 100: 3.8.10 Step 20: 3.9.1 Step 10: 3.9.1 Step 20: 3.10.2 Step 10: I have found the way to sort by first number on this site:

Why would I need use fflush on stdout before writing to stderr?

你离开我真会死。 提交于 2021-02-04 11:33:50
问题 I am reading 'UNIX Network Programming: The Sockets Networking API' and in the example code they have an error handling function which contains the following lines: fflush(stdout); /* in case stdout and stderr are the same */ fputs(buf, stderr); fflush(stderr); Where buf contains the error description. I don't understand why fflush is used on stdout on the first line and why the comment explains the reason for its use. 回答1: This is because of buffering. Stdout and stderr are usually buffered

How to conveniently sync a file between two git repositories

三世轮回 提交于 2021-02-04 10:25:08
问题 I have two git local repositories. Both share an identical file, under a different path and under a different name. Currently, when I make changes I have to copy the file from one directory to another. Is there an alternative way to keep them in sync without manually overwriting the file? I don't want to create a separate repository for this file. I thought one of the following things would work, but apparently, they don't: git submodule git subtree symlink soft symlink hard What else is

Create shared library with undefined reference using gcc, Unix/Windows differences

扶醉桌前 提交于 2021-01-29 21:13:25
问题 I want to build a simple library with some undefined reference, as you can see in function_two.c , I call three() which is not defined. header.h void one(); void two(); void three(); function_one.c #include <stdio.h> #include "header.h" void one() { printf("one\n"); } function_two.c #include <stdio.h> #include "header.h" void two() { printf("two\n"); three(); } Using Linux , I compile both files and then I link them linux:~/example$ gcc -c -Wall -Werror -fpic function_one.c linux:~/example$

A UNIX Command to Find the Name of the Student who has the Second Highest Score

╄→гoц情女王★ 提交于 2021-01-29 20:08:55
问题 I am new to Unix Programming. Could you please help me to solve the question. For example, If the input file has the below content RollNo Name Score 234 ABC 70 567 QWE 12 457 RTE 56 234 XYZ 80 456 ERT 45 The output will be ABC I tried something like this sort -k3,3 -rn -t" " | head -n2 | awk '{print $2}' 回答1: Using awk awk 'NR>1{arr[$3]=$2} END {n=asorti(arr,arr_sorted); print arr[arr_sorted[n-1]]}' Demo: $cat file.txt RollNo Name Score 234 ABC 70 567 QWE 12 457 RTE 56 234 XYZ 80 456 ERT 45

How do I print the current working directory of another user in linux?

为君一笑 提交于 2021-01-29 16:13:39
问题 Is there a command line I can issue to see what directory another user is currently working in? This would be like using >pwd but for the other user. 回答1: There's a cwd symlink in every process' /proc folder, but as a commoner you wouldn't have any rights to read any other's proc folder - only your own: [marc@panic home]$ ls -l /proc/$$/cwd lrwxrwxrwx. 1 marc marc 0 May 5 12:06 /proc/16257/cwd -> /home ^^^^^---cwd [marc@panic home]$ ^^^^---cwd 来源: https://stackoverflow.com/questions/23478833

no pg_hba.conf entry for host / Connect call failed / Invalid data directory for cluster 12 main - Postgresql Ubuntu

丶灬走出姿态 提交于 2021-01-29 15:40:28
问题 I'm trying to move my bot to an Ubuntu virtual server from Vultr but it's having a problem connecting to the postgres database. I've tried editing the config from md5 to true, and host to local, etc. But those only give me different errors and also make it stop working on my original machine too. It's working perfectly fine on my Windows machine. Here is the error I'm facing: asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "[local]", user "postgres",

Storing and accessing an array of struct from shared memory

為{幸葍}努か 提交于 2021-01-29 09:31:22
问题 I am writing a program on a hotel reservation system and have declared a struct Room as follows: struct Room { bool isavailable; bool ispaid; string customer; string date; }; I use a variable read from an input file to create an array of n structs which is all the rooms in the hotel. struct Room* rooms = new Room[numOfRooms]; I then create the shared memory space and attach it, but when I try to access it after, it doesn't seem to work. //creates shared memory space if((shmid = shmget(shmkey,