shell 检查一个单词是否在字典中

#!/bin/bash
#文件名:checkword.sh
word=$1
grep "^$1$" /usr/share/dict/linux.words -q
if [ $? -eq 0 ];
then
echo $word is a dictionary word;
else
echo $word is not a dictionary word;
fi

shell 检查一个单词是否在字典中

时间: 2024-08-01 02:30:20

shell 检查一个单词是否在字典中的相关文章

检查一个单词是否为其他字符串的子串

假定一个方法isSubstring.可检查一个单词是否为其他字符串的子串.给定两个字符串s1和s2.请编写代码检查s2是否为s1旋转而成,要求只调用一次isSubstring.(比如,waterbottle是erbottlewat旋转后的字符串) 上述分析正是这个问题的解法:直接调用isSubstring(s1s1,s2)即可. bool isRotation(string s1, string s2) { int len = s1.length(); /*检查s1和s2是否等长且不为空*/ i

[LeetCode] Longest Word in Dictionary through Deleting 删除后得到的字典中的最长单词

Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographic

<!-- str.startsWith('胡') 检查一个 字符串中是否有某字符 返回true false -->

1.<!-- str.startsWith('胡')  检查一个 字符串中是否有某字符 返回true false --> 2. vh 分享到选择其它项 复制本页链接 版本:CSS3 补充完善,提交问题欢迎微博上 @愚人码头 说明: 相对于视口的高度.视口被均分为100单位的vh 示例代码: h1 { font-size: 8vh; } 如果视口的高度是200mm,那么上述代码中h1元素的字号将为16mm,即(8x200)/100 兼容性: 浅绿 = 支持 红色 = 不支持 粉色 = 部分支持

Java 高效检查一个数组中是否包含某个值

如何检查一个数组(未排序)中是否包含某个特定的值?在Java中,这是一个非常有用并又很常用的操作.同时,在StackOverflow中,有时一个得票非常高的问题.在得票比较高的几个回答中,时间复杂度差别也很大. 1.不同的实现方式 使用list 1 public static boolean useList(String[] arr, String targetValue) { 2 return Arrays.asList(arr).contains(targetValue); 3 } 使用se

七、如何在Java中高效检查一个数组是否含有一个值

如何检查一个数组(非排序的)是否包含特定的值.这是个非常有用或经常被在Java中使用.这是个在Stack Overflow中高得票的问题.在已经高得票的答案中,有许多不同的处理方法,但是时间的复杂度非常不同.在下面,我将会展示每种方法的时间花费. 一.四种不同的方法去检查一个数组包含特定的值 1) 用List public static boolean useList(String[] arr, String targetValue) { return Arrays.asList(arr).co

《Python CookBook2》 第一章 文本 - 过滤字符串中不属于指定集合的字符 &amp;&amp; 检查一个字符串是文本还是二进制

过滤字符串中不属于指定集合的字符 任务: 给定一个需要保留的字符串的集合,构建一个过滤函数,并可将其应用于任何字符串s,函数返回一个s的拷贝,该拷贝只包含指定字符集合中的元素. 解决方案: import string allchars = string.maketrans('','') #all chars table def makefilter(keep): delchars = allchars.translate(allchars,keep) def thefilter(s): retu

leetcode—58 Length of Last Word Total(字符串中最后一个单词的长度)

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-space cha

编写一个程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词

#include<iostream> #include<string> #include<vector> using namespace std; int main() { string maxStr,Str1,Str2; int maxNum,Num1,Num2; if(cin>>Str1) Num1=1; maxNum=0; while(cin>>Str2) { Num2=1; if(Str2==Str1) Num2=++Num1; if(N

检查字典中是否有NULL 类型,如果有的话,转换成&quot;&quot;,因为字典中又null ,是不能存入到NSUserDefalut 里面的.

//该方法是检查字典中是否有nil 的,有nil就转行成"" - (NSDictionary *)checkDict:(NSDictionary *)sender { NSMutableDictionary * dict_mutable = [[NSMutableDictionary alloc] init]; NSArray * keys = sender.allKeys; for (NSString * key in keys) { if ([[sender objectForKe